in reply to Getting element of array with a match

Hashes are good for determining uniqueness of things. The grep tests every value in @array2 and populates @common with each value that returns true.
#!/usr/bin/env perl use strict; use warnings; use Data::Dump; my @array1 = (1,2,3,4); my @array2 = (4,5,6,7); my %hash; @hash{@array1} = undef; #Hash Slice populates keys of hash using value +s from array my @common = grep { exists $hash{$_} } @array2; dd @common; #4