in reply to matching several lines

Instead of slurping, process one line at a time:

SKIP: while ( <> ) { next SKIP if !/^AAAAAA/; PRINT: while ( <> ) { last PRINT if /^BBBBBB/; print; } }