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. }