in reply to printing specific lines

use strict; my ($handle, @lines, $c); open($handle, "lines"); @lines = <$handle>; close($handle); chomp @lines; @lines = sort {$a <=> $b} @lines; open($handle, "text"); while ($c <= $#lines) { <$handle> for (($.)..($lines[$c++]-2)); print $_ = <$handle>; } close($handle);
This assumes that line 1 is considered the first line, not the second. It allows for line numbers given out of order, and doesn't require reading the entire text into memory at once.