foreach my $item ( (@array1, @array2) ) { if ( $item =~ /$pattern/i ) { @array1 = grep { $_ != $item } @array1; } }