in reply to Help to infinite loop

In these cases you can use perl debugger(man perldebug) to know what is your program really doing.
One more idea would be to use print STDERR Message, where STDERR is unbuffered.