my $stopmatch = join '|', sort { length $b <=> length $a } qw(car pet carpet); $stopmatch = qr/\b(?:$stopmatch)\b/;