while ($test =~ s{\[\[(.+?)[^\]\]]}g) { print "FOO: $1\n"; }