I suspect your problem is that perl buffers output, i.e.
the output aint printed immediatly but later for some
efficiency reason. Output to STDOUT typically is line
buffered, that means it should be written when you send a
newline (\n)...
setting the $OUTPUT_AUTOFLUSH variable ($|)
to some value other than 0 will help.