Perl completes logical xor with an assignment operator
Perl 5.41.13 adds ^^= after the earlier introduction of ^^. The small addition exposes useful distinctions between logical evaluation, bitwise operations, and assignment precedence.
Perl 5.40 introduced a punctuation spelling for logical exclusive-or, but its assignment form was missing. Today's development release fills that omission with ^^=. The 5.41.13 release notes describe it as the assigning variant of the medium-precedence ^^ operator. The history records date the release to May 28.
The change is small enough to explain through the distinctions around it. Logical exclusive-or asks whether exactly one operand is true. Compound assignment stores the result back into a scalar. The punctuation family gives that combination a direct spelling, while retaining the evaluation requirements of exclusive-or.
I still find Perl useful for short text programs, where an expression can carry most of an operation. Small additions to its punctuation deserve exact explanations because similar-looking operators can mean different things. Here the extra caret distinguishes a logical question from the separate bitwise operator family.
Exclusive-or needs both operands
The operator documentation shipped with this release says ^^ evaluates both operands and returns true only if exactly one is true. This differs from the short-circuit behavior of && and ||. Those operators can determine their answer from the left operand in some cases.
Exclusive-or cannot make that decision after seeing only one value. If the left operand is true, the result still depends on whether the right operand is false. If the left operand is false, the result depends on whether the right operand is true. Both cases require the second operand's truth value.
A compact example can update a Boolean state from another Boolean value. This code targets the development interpreter that implements the new assignment spelling.
use v5.40;
my $selected = 1;
my $toggle = 1;
$selected ^^= $toggle;
say $selected ? "selected" : "not selected";
Both initial values are true, so the resulting state is false. Changing $toggle to false would preserve a true result in this example. The operation expresses truth-value combination, so the code prints through a conditional instead of assuming a particular displayed representation for false.
The version declaration supplies a language baseline, while the operator requires the newer development implementation. The release notes identify ^^ as a 5.40.0 addition and ^^= as today's addition. A program using the latter therefore cannot infer availability from the earlier operator's existence alone.
Assignment supplies storage semantics
The same operator documentation describes compound assignment through an arithmetic example. $x += 2 corresponds to assigning the addition result to $x, while avoiding duplicated side effects that dereferencing the left-hand side might trigger. The other assignment operators follow the same general model.
That matters beyond saving characters. Rewriting a compound assignment as two textual copies of its left operand can duplicate work associated with locating the destination. The documentation mentions tied values as an example of observable effects. Compound assignment gives the language a defined operation for accessing and updating the scalar destination.
The new spelling belongs to that existing family. It combines logical exclusive-or with assignment rather than introducing a separate storage mechanism. A simple scalar makes the relationship easy to see, but the documented compound-assignment model also explains why the operator is more specific than an arbitrary source-level abbreviation.
These combined operators operate on scalars. Ordinary assignment has broader uses, including list and array assignment, but that does not make each compound form an aggregate operation. Applying ^^= should be understood as updating one scalar through the logical operation, not as independently combining corresponding elements of two lists.
Precedence remains part of the meaning
Perl already has the word operator xor. Its documentation places it among the low-precedence logical operators. The punctuation operator introduced in 5.40 gives exclusive-or a different precedence choice. That distinction is useful wherever an expression also contains assignment or other operators whose grouping affects the result.
The documentation warns about analogous mistakes with or and ||. A word-form logical operator can be useful for control flow after an assignment because of its low precedence. Substituting it into an expression intended for the punctuation form can change grouping. The shared logical vocabulary does not make the syntax interchangeable.
All the compound assignment operators have assignment precedence, even though the documentation groups them into families. The grouping in a reference list explains their relationships, while precedence determines how a complete expression parses. The new operator should therefore be read as an assignment operation when it appears alongside surrounding expressions.
My preference is to keep this kind of Boolean update visibly simple. A scalar destination and a clearly named Boolean input make the operation's purpose apparent. Saving punctuation is of little benefit when the surrounding expression makes the reader reconstruct precedence before understanding which value changes.
The release also preserves the distinction between logical and bitwise operations. ^^= completes the logical exclusive-or family associated with ^^. Its purpose is to store the result of a truth-value calculation. The missing assignment form has now been supplied in the development series, with the established scalar assignment rules and the requirement to evaluate both logical operands.