my @sets = sort(keys(%HoHoA)); while(@sets) { my $set1 = shift(@sets); foreach my $part1 (sort(keys(%{$HoHoA{$set1}}))) { #note that the earlier shift has already taken off #the part we don't want to match against foreach my $set2 (@sets) { foreach my $part2 (sort(keys(%{$HoHoA{$set2}}))) { print "$part1 - $part2\n"; } } } }