The
next statement you have is essentially useless -- it breaks out of the inner for-loop only, which means that the
push is always executed. this could be resolved by using a label so that the next applies to the outer for loop, or by using a boolean flag, but consider a different approach -- a hash to provide a dictionary (grep would be natural, but inefficient in this case):
my %stopwords = map { $_ => undef } @stopwords;
$/=" ";
while(<>){
chomp;
push @lessWords, $_ unless exists $stopwords{$_};
}
Update: An after-thought rewrite:
my %stopwords = map { $_ => undef } @stopwords;
$/=" ";
@lessWords = grep( exists $stopwords{$_}, map {chomp; $_} <> )