$a = "A1"; $b = "B2"; printf("a: %s b: %s\n", $a, $b); $a =~ tr/[12]/[21]/; $b =~ tr/[12]/[21]/; printf("a: %s b: %s\n", $a, $b);