my %arr1_as_hash; @arr1_as_hash{@arr1} = (); my @arr3 = map { $_->[1] } grep { exists $arr1_as_hash{$_->[0]} } map { [ split /,/ ] } @arr2;