my @set1 = qw (apples oranges pears mangoes); my @set2 = qw (bananas mangoes papayas coconuts); my %first_set; @first_set{@set1} = (); my @union = grep { exists $first_set{$_} } @set2;