#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 5; my @yesmatch = ('of', 'of the blue', 'the blue of', 'ending with of'); my @nomatch = ('out of blue'); my @stopwords = qw/a of the/; for my $phrase (@yesmatch) { ok (stopped($phrase, \@stopwords), "$phrase stopped"); } for my $phrase (@nomatch) { ok ((not stopped($phrase, \@stopwords)), "$phrase not stopped"); } sub stopped { my ($phrase, $sw) = @_; my $rev; for my $word (@$sw) { return 1 unless index ($phrase, $word); $rev //= reverse $phrase; return 1 unless index ($rev, reverse $word); } return 0; }