while() { if(/\bREGEXP\b/) { $seen++; push(@lines, $.); print "\nMatch found:\n\n\tFILENAME: $dir/$file\n\tLINE: $. : '$`~$&~$'"; if(($.) .. ($. + 3) { print; } # my range extract code # OR print "$`$&$'\n" if(($.)..($. + 3)); # my range extract code }else { next; } }