my $test = qq|==Getting There== testing [ref]bla bla bla [[http://www.google.com]] test and [[http://www.google.com\|testing]] [/ref] hhh testing [ref]bla bla bla an[/ref] hhh |; while ($test =~ m%\[ref\](.*)\[/ref\]%gix) { print "FOO, $1 \n"; }