#!/usr/bin/perl use strict; use warnings; my $cur = -10; my $x = qr'Begin'; my $y = 3; while () { $cur = $. if /$x/; print if ($.>$cur and $.<=$cur+$y); } _ _DATA_ _ Hello Welt Begin Test ALPHA BETA GAMMA DELTA