open IN,"<",$fileName or die "Can't open $filename: $!"; while () { # read line from IN handle to $_ if ($. == $some_number || $. == $some_other_number) { # $. is the current line number # do stuff with the line in $_ } last if $. > $last_interesting_line_number; } close IN;