for ( 'A_TAG_HSSL_LBA_1', 'A_TAG_HSSL_LBAB_1' ) { if( ! /A_[A_Z0-9_]+/i) { print "$_ is not matching\n"; } else { print "$_ matches\n"; } } #### A_TAG_HSSL_LBA_1 matches A_TAG_HSSL_LBAB_1 is not matching #### /^ # start of string A_ # must start "A_" [A-Z0-9_]+ # at least one capital, digit or underscore $ # end of string /ix # allow spaces and comments inside regexp # and ignore case ####