I'd use List::Compare (though I'm not sure I like its object-oriented interface)
Then use the same author’s List::Compare::Functional instead :-)
#! perl
use strict;
use warnings;
use feature qw/ say /;
use List::Compare::Functional qw/ get_unique get_complement /;
use List::MoreUtils qw/ uniq /;
my %hash1 = (abc => [1, 2, 3, 4]);
my %hash2 = (abc => [1, 3, 5, 7]);
$, = ',';
foreach my $key (uniq(keys %hash1, keys %hash2))
{
say get_unique ( [ $hash1{$key} // [], $hash2{$key} // [] ] );
say get_complement( [ $hash1{$key} // [], $hash2{$key} // [] ] );
}
Output:
13:23 >perl 1000_SoPW.pl
2,4
5,7
13:23 >
Hope that helps,