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