http://www.perlmonks.org?node_id=764057


in reply to behaviour of STDOUT and STDERR

You're Suffering from buffering. Put this before print():
$| = 1; # disable buffering STDOUT