#!/usr/bin/perl use warnings; use strict; my @words = ("of the blue","the blue of","out of blue"); my @stopwords= ("a","the","of"); foreach my $word (@words) { if (grep{$word =~ /^$_/i or $word =~ /$_$/i}@stopwords) { print "Stopword $word discarded\n"; } else { print "$word is not a stop word\n"; } } __END__ Stopword of the blue discarded Stopword the blue of discarded out of blue is not a stop word