First you extract the keys from the hashes into lists, then solve the "removing duplicates" problem described above. For example:
%seen = (); for $element (keys(%foo), keys(%bar)) { $seen{$element}++; } @uniq = keys %seen;Or more succinctly:
@uniq = keys %{{%foo,%bar}};Or if you really want to save space:
%seen = (); while (defined ($key = each %foo)) { $seen{$key}++; } while (defined ($key = each %bar)) { $seen{$key}++; } @uniq = keys %seen;