my $lineid = 0; while ($lineid < 20) { my $linedata = $connect->getline; # check for eof or time-out _before_ using the data last if $connect->eof or $connect->timed_out; # now save the line push(@data,$linedata); $lineid++; }