@x = qw (1 2 3); @y = qw (3 4 5); my %v = map {$_=>1} @x; my %w = map {$_=>1} @y; for (@x,@y) { push @z,$_ if $v{$_} and !$w{$_} } print (@z);