http://www.perlmonks.org?node_id=266193

Q&A > arrays > How can I find the union/difference/intersection of two arrays? - Answer contributed by DrHyde

TheDamian's Quantum::Superpositions module can do this. Although it is slow, the code is quite readable:
use Quantum::Superpositions; my @a = (1,2,3,4,5,6,7,8,9,10); # integers my @b = (2,4,6,8,10,12,14,16,18,20); # doubled my @unionAB = sort { $a <=> $b } eigenstates( any(@a, @b) ); my @intersectionAB = sort { $a <=> $b } eigenstates( any(@a) == any(@b +) ); my @differenceAB = sort { $a <=> $b } eigenstates( any(@a) != all(@b +) );