#...code filling the arrays #@A = DB list #@B = array of data my %seen; # lookup table my @aonly; # info only in list @A my @bonly; # info only in list @B # build lookup table @seen{@B} = ( ); foreach $item (@A) { push(@aonly, $item) unless exists $seen{$item}; } %seen = (); @seen{@A} = ( ); foreach $item (@B) { push(@bonly, $item) unless exists $seen{$item}; } #@aonly = unique to DB list - @A #@bonly = unique to array of data - @B #continue on your merry way...