How can I get the unique keys from two hashes?

First you extract the keys from each into arrays, and then solve the uniquifying the array 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 (($key) = each %foo) {
        $seen{$key}++;
    }
    while (($key) = each %bar) {
        $seen{$key}++;
    }
    @uniq = keys %seen;