in reply to How to not match some words but match all the others
my %subst; $subst{$_}++ for qw/foo bar baz/; s/(\w+)/$subst{$_} ? subst($1) : $1/ge;
Indeed you may also hide the hash lookup into a separate subst sub, if you have one: of course you're not required to, I wrote it like so just for illustrational purposes...
You may even put code refs into the hash to differentiate the behaviour for different (sets of) words. Briefly, the answer(TM) is 42^W/e!
|
|---|