in reply to assign array to hash

Do you really need the array? A bag-of-word is independent of word order, but with the keys keyword you'll have access to all your words.

sub toBagOfWords { my %bag; $bag{$_}++ for split /\s+/, shift; %bag; } my %hash = toBagOfWords "I see their knavery this is to make an ass of + me"; my @words = keys %hash; # if you still need the list of word, in a "ra +ndom" order