Swapping letters with regexp

perl, regex, replace

Solution

Use the transliteration operator:

$str =~ y/oe/eo/;

E.g.

$ echo "Absolute force" | perl -pe 'y/oe/eo/'
Abseluto ferco

Problem

How can I swap the letter `o` with the letter `e` and `e` with `o`? I just tried this but I don't think this is a good way of doing this. Is there a better way? ``` my $str = 'Absolute force'; $str =~ s/e/___eee___/g; $str =~ s/o/e/g; $str =~ s/___eee___/o/g; ``` Output: `Abseluto ferco`

Original source