in reply to Return variable hangs script

Do you have access to the error_log?

I'm guessing that if you don't use strict, maybe you also don't use my so you have global variables all over the place. Is $count a lexical variable, or are you overwriting a global one? For example, if $count determines when a while loop stops, but you kept resetting it to a non-zero value.....