@ary1 = grep {!exists $h2{$_} or $dupes{$_}=0} @ary1; @ary2 = grep {!exists $h1{$_} } @ary2;