my $re= qr{\[\[ # opening delimiter ( # capture... (?: # a group (?!\]\]) # that does not start with ]] . # and is a single character long )+ # and many of these groups, at least one. ) ]] # closing delimiter }x; while ($test =~ m{$re}g) { print "FOO:<$1>\n"; }