And if this solution is appropriate for your problem, but you're suffering from performance issues (something which may show up because you're doing over and over so many passes at your data as the number of your words), you may give a try to Regexp::Assemble. Regexp::Assemble may be used to automatically build a regexp which matches all your words without hassle and possibly optimized with respect to one you wrote by hand.
use Regexp::Assemble;
my $ra = Regexp::Assemble->new;
$ra->add(@words);
my $re = $ra->re;
s/$re//gsi; # this will replace
# foreach (@words) { ... s/// ... }
# and do the word deletion in one go
The above assumes your words don't need quoting to become regexes.
Also it may be handy the method add_file to read your stopwords file and assemble the regex in a single action. |