I don't know how it benchmarks, and would need to be convinced that it matters. ;) However, here is another way to do it.
my %swaps = ( foo => 'bar', bar => 'foo' ); $str =~ s/(foo|bar)/$swaps{$1}/g
Dave
In reply to Re: Swap foo and bar in text?
by davido
in thread Swap foo and bar in text?
by Cody Fendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |