Darn, and I didn't even get a go at solving it! :-)
But ,just goes to show that the good old "debug" routines are worth writing.
Small print statements like
if ($debug) { print "DEBUG: var1:".$var1."\nvar2:".$var2 };
really make your day in cases like this!