my $line_count = 0; while (my $line = <>){ $line_count++; next if ($line_count <= $last_line_read); # the rest of you code from the while remains the same }