in reply to range of lines

This probably isn't the most clever way, but it'll do the job: set a counter to the number of lines you want to print out after data matches the pattern, and then 1) print out the line if the counter is positive, and 2) decrement the counter for each line that's printed out.

use warnings; use strict; my $nLines = 0; while (<DATA>) { $nLines = 5 if /kjkjkjkj/; print if $nLines-- > 0; } __DATA__ 1asdfasdf 2asdfasdf 3kjkjkjkjkj 4asdfasdf 5asdfasdf 6asdfasdf 7asdfasdf 8asdfasdf 9asdfasdf 10asdfasdf

Outputs:

3kjkjkjkjkj
4asdfasdf
5asdfasdf
6asdfasdf
7asdfasdf