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