while(){ if (/2/){ my $skip=2; print "skipping $skip lines\n"; while $skip-- >0 and not eof DATA; next; } if (/5/){ print "high five\n"; next; } if (/3/){ print "I am not here\n"; next; } print; } __DATA__ 1 1 2 3 4 4 5