my $lbl; # lookback line while ($buff[$.%($lb+1)] = ($_ = )) { print $lbl if $lbl = $buff[($.+1)%($lb+1)] and /$match/; }