@union = union(\@a, \@b); @inter = intersection(\@a, \@b, \@c); @diff = difference(\@a, \@b); @in_a = unique_to(\@a, (\@b, \@c)); sub union { my %seen; @seen{@$_} = () for @_; return keys %seen; } sub intersection { my %seen; for (@_) { $seen{$_}++ for @$_ } return grep $seen{$_} == @_, keys %seen; } sub difference { my %seen; for (@_) { $seen{$_}++ for @$_ } return grep $seen{$_} == 1, keys %seen; } sub unique_to { my %seen; @seen{@{ shift() }} = (); delete @seen{@$_} for @_; return keys %seen; }