use strict; use warnings; use List::Compare; use Data::Dumper; my @array1=('a','2','3','2'); my @array2=('1','2','3','2'); my $lc = List::Compare->new(\@array1, \@array2); # Get those items which appear at least once in both lists (their intersection). my @intersection = $lc->get_intersection; print Dumper \@intersection;