in reply to Swapping two parts of a string

Capture the two strings to be swapped using a regex then put them back together in opposite order:

$origin =~ s/\( ([^ ,]+) \s*,\s* ([^ )]+) \) /($2 $1)/x;

Note that the /x allows the spaces to be used to break up the expression for easier understanding.


DWIM is Perl's answer to Gödel