my %hashOfAllElements = (); foreach $element (@array1, @array2) { $hashOfAllElements{ $element }++; } my @array3 = keys %hashOfAllElements;