use strict; my @a=qw(a b c d); my @b=qw(b a e f); my %h; my @m = map {$h{$_}++ ? $_ : ()} (@a, @b); print @m; print "\n";