in reply to using s/ to not only substitute but also modify text

Here ya go:
my $foo = 'bar 123 moo cow'; print "$foo\n"; $foo =~ s/(123)/function($1)/e; print "$foo\n"; sub function { my $argument = shift; $argument = "rab"; return $argument; }


-Waswas