while ($input =~ /\G(.*?)\[\[([^]]+)\]\]/sg) { my $link = $2; $output .= $1; $output .= process($link); }