use IO::Select; # code to initialize $sock my $sel = new IO::Select( $sock ); while (1){ if ($sel->can_read(5 * 60)){ # see if $sock has data. # wait no longer than 5 min while (<$sock>){ # read however many lines you expect } }else{ # log error } } #end while