in reply to Comparing arrays in perl.

The standard way to get rid of duplicates is:

my %seen; my @filtered = grep !$seen{$_}++, @arr2;

The difference is that you only want to remove duplicates of elements present in @arr1. Let's adapt the above:

my %seen; my %in_arr1 = map { $_ => 1 } @arr1; my @filtered = grep !$in_arr1{$_} || !$seen{$_}++, @arr2;