# is element $a in the set? exists $set{$a} # remove $a from the set delete $set{$a}; # add $a to the set $set{$a} = undef; # get the list of elements in the set keys %set # create the union %union = (%set1, %set2); # create the intersection for (keys %set1) { $intersect{$_} = undef if exists $set2{$_}; } # create the difference for (keys %set1) { $diff{$_} = undef unless exists $set2{$_}; } for (keys %set2) { $diff{$_} = undef unless exists $set1{$_}; }