if ($before eq 'Z' xor $after eq 'Z') { # change from A|B <=> Z }