map decode("KOI8-R", $_), keys %$stopwords;
The problem is that your stopwords are left undecoded in the hash. You should produce a new hash containing transformed keys instead of throwing the results of
decode out:
my %stopwords;
undef @stopwords{
map decode("KOI8-R", $_), keys %{getStopWords('ru')}
};
Also, the stop words are in lower case, which means that you should lowercase your text too before checking whether it's a stopword or not.
say join ' ', grep { ! exists $stopwords{lc $_} } @words;
You may want to
split your text on
/\W+/ to get the words in one operation.
Успехов,