my @array = qw/one one two/; # your algorithm print @uniques; # prints 'two' # and I would expect 'onetwo'