>perl -wMstrict -le "use List::MoreUtils qw(part); use Data::Dump qw(pp); ;; my @source = (1, 2, 3, 4, 5, 7); my @target = (0, 1, 3, 4, 6); ;; my %diff; ++$diff{$_} for @source; --$diff{$_} for @target; ;; my ($ar_in_t_not_s, undef, $ar_in_s_not_t) = part { 1 + $diff{$_} } keys %diff; ;; print 'in t not s: ', pp $ar_in_t_not_s; print 'in s not t: ', pp $ar_in_s_not_t; " in t not s: [6, 0] in s not t: [7, 2, 5]