#!/usr/bin/perl -w use strict; LINE: while ( ) { MATCH: while ( m#(.*?)#gi ) { print "$1\n" if ( $1 !~ /foo/ ); } } __DATA__ This has no match at all, and is skipped. This has foo, but is skipped with no code block. This is acceptable so is an embedded block, and the next. is foo rejected foo we will skip with no terminator. and, we will also skip with foo, but no terminator. foo that preceeds just simple text is accepted. here is another example. but Perl will accept foo outside the block. The foo can be in advance, as every hacker knows. Doubled matches like foo are evil. This should skip the second loop foo . This foo should skip the first loop .