in reply to Re^2: How do I pass $1 to s///?
in thread How do I pass $1 to s///?

You can pass any Perl source code in the above snippet (which is why it's potentially dangerous).

One templating system would be the Template Toolkit.

use Template; sub foo { my $template = Template->new(); (my $text = $_[0]) =~ s/$_[1]/ my $output = ''; my @matches = map { substr($text, $-[$_], $+[$_] - $-[$_]) } 1 .. $#-; $template->process(\$_[2], { matches => \@matches }, \$output); $output /e; print $text; } foo("This is test 1\n", qr/test (.*)/, 'fish [% matches.1 %]');

(Untested)