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


in reply to use sysread to read non-blocking filehandle

while ($bytes_read) { my $buf; $bytes_read = sysread($out, $buf, $blocksize); ...

Your code leaves the loop as soon as there is nothing to read on a socket.

while( <$fh> ) will read things until it encounters a newline.