use strict; use warnings; while () { next if ! (/Line above/ .. /Line below/); next if ! /Description\s+"([^"]*)"/; print "Found $1 in line $.\n"; } __DATA__ Line above Description "xyz" Line below Line above Line below