in reply to multiple (different) substitutions on same $foo
Here's an alternative way to do it, doing the whole search and replace as a oneliner:
my $foo = "The frog kissed the woman and became a man."; $foo =~ s/\b(frog|woman|man)\b/{frog=>toad,woman=>girl,man=>boy}->{$1} +/eg;
I've added a \b for you, see comment further up
This assumes you meant to have a /g-switch after every substitution. I couldn't find a way to match only the first "man" and "woman", but I'm sure it will keep me awake tonight.
|
|---|