in reply to Multiple replacements with the exception of previously made replacements.

Why not use the tr/y operator - described (here)?
use warnings; use strict; my $test = 'x x x a x x x b x x x a x x x b x x x'; warn $test; (my $res = $test) =~ y/[ab]/[ba]/; warn $res;
$ perl tst.pl x x x a x x x b x x x a x x x b x x x at tst.pl line 5. x x x b x x x a x x x b x x x a x x x at tst.pl line 8.
A user level that continues to overstate my experience :-))