# create a hash representing @array2 my %hash; $hash{$_} = undef foreach (@array2); # grep only leaves what evaluates to true. # if an element of array1 is not in array2, it is # left in place @array1 = grep { not exists $hash{$_} } @array1; #### if($array1[$search] eq $array[$search2]){ splice(@array1,$search,1); # remove 1 element from index $search in @array1 $search--; # the next element is already at $search. decrement so when it's incremented we'll have the same value. }