use Data::Dump qw(pp); my @array1=(1..5); my @array2=(3..7); my (%union,%intersection,%difference,@tmp); my (%set1,%set2); @set1{@array1}=@array1; @set2{@array2}=@array2; @tmp= @set1{ keys %set2 }; @intersection{@tmp}=@tmp; # warning: use of uninitialized values delete $intersection{""} ; # dirty hack %union=(%set1,%set2); %difference=%union; delete @difference{keys %intersection}; pp \(%set1,%set2,%union,%intersection,%difference); #### Use of uninitialized value $tmp[0] in hash slice at /home/lanx/B/PL/PM/set.pl line 17. Use of uninitialized value $tmp[3] in hash slice at /home/lanx/B/PL/PM/set.pl line 17. ( { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5 }, { 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7 }, { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7 }, { 3 => 3, 4 => 4, 5 => 5 }, { 1 => 1, 2 => 2, 6 => 6, 7 => 7 }, )