my %stopwd; open( LIST, "my_stopwords.txt" ) or die "$!"; while () { chomp; $stopwd{$_} = undef; # assume one word per line } close LIST; # now, to remove stopwords, split the input data ($_) on \b # and check each token: my $filtered = join '', map { exists($stopwd{$_}) ? '':$_ } split /\b/;