In addition to the perl idiom of using a list assignment to swap values without a temporary variables, there is the idiom using the XOR operator. Although this does take three statements and doesn't fully take advantage of perl's list assignments, and so is more useful in other languages.

As I've pointed out before, using XORs to swap values in perl will not work with references. (Note, by the way, that the OP was an inquiry about swapping references.)

References aren't the only values this naive method will break on. Try it with $a = 1; $b = "0foo"; for instance.

In C or assembly, you can swap values with bitwise XOR to avoid the use of temporary storage. It's rarely necessary, but comes in handy when you need things to be real fast and you have a limited number of registers. In such lower level languages, it works on strings because strings are pointers and pointers are ints and XOR works nicely on ints. In perl, however, the XOR method will do a bitwise XOR on the whole string. When all you want to do is swap values, that's grossly inefficient.

Bitwise XOR should never be used to swap values in perl. It isn't maintainable. It isn't efficient. It isn't clever. Don't do it.

In languages like C (and not Perl) where it sometimes makes sense to use this method for swapping values, it will work just fine even if the values are the same. I'm unsure what you mean by "overlap." To see that it will work, try it with all four combinations of 2 bits: