http://www.perlmonks.org?node_id=117851


in reply to Extract lines and output...

There are so many ways to do this. Maybe straightforward, don't print until $. is 4 (see perlvar):
while(<>){ next if $. <4; #codeblockdoingsomeotherthings print; }

HTH,

Jeroen

Update: I couldn't resist adding some more possibilities:

#1 slurping the whole thing in memory, and splice @file = <>; splice @file, 0, 4; print @file; #2 using the flip-flop operator while (<>){ next unless $.>3 .. 1; #... print; } #3 another flip-flop $start = -3; while (<>){ next unless $start++ .. 1; #.... print; } #4 just repeat 4 times $dummy=<> for 1..4; #5 make it multifile proof while (<>){ close( ARGV) if (eof);  next unless $.>3 .. eof; #... print; }