in reply to Further question on removing elements from arrays

You can use grep.

my (%a, %b); @a{@a} = (); @b{@b} = (); @a = grep {exists $b{$_}} @a; @b = grep {exists $a{$_}} @b;
Now @a and @b should be equal, containing only the common elements.

Added - fixed missing curlies, tlm++.

After Compline,
Zaxo