This snippet might be helpful, and there are modules for checking lists.
#!/usr/bin/perl
my @a = qw(a b c d e f);
my @b = qw(c d e f g h);
my ($only_a, $only_b, $both, $either) = listy(\@a, \@b);
print "only in a: @$only_a\n";
print "only in b: @$only_b\n";
print "both: @$both\n";
print "either: @$either\n";
sub listy {
my %tmp1;
for (0..1) {
for my $k (@{$_[$_]}) {
$tmp1{$k} .= $_;
}
}
my %tmp2;
while (my($k, $v) = each %tmp1) {
push @{$tmp2{$v}}, $k;
}
return @tmp2{"0", "1", "01"}, [keys %tmp1];
}