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

Is there any way to achieve this with a single s/// operation?

How about with zero s/// operations? (Use tr/// instead :)

[0] Perl> $s = 'x x x a x x x b x x x a x x x b x x x';; [0] Perl> $s =~ tr[ab][ba];; [0] Perl> print $s;; x x x b x x x a x x x b x x x a x x x

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)