use warnings; use strict; use Data::Dumper; my @Definition=("NN", "NNS"); my ($defs) = map { qr/$_/ } join '|', map {quotemeta} sort { length $b <=> length $a } @Definition; for my $str ( "ABC", "NXY", "NNF", "NNSX" ) { print "$str: ", $str=~/^$defs/ ? "yes!\n" : "no\n"; } __END__ ABC: no NXY: no NNF: yes! NNSX: yes!