while (m/\[\[(\w+)\]\]/) { my $foo = $helper->($1); s/\[\[(\w+)\]\]/$foo/; }