in reply to exact word match
Square brackets are for matching individual characters. The regex you wrote will reject (because of ^) any word that has any of 'm', 'a', 's', 't', 'e', 'r', '|' .. and so on.
If you meant a valid database name except the names given in your regex you could have written
if($name =~ /^[a-z0-9_]$/i && $name !~ /^(?:master|model|dbccdb|sybsec +urity|sybsystemdb|sybsystemprocs|tempdb|DBA)$/) { print "allowed\n" } else { print "not allowed\n" }
Update: This can also be written in a single regex using negative look-ahead assertion as follows
if($name =~ /^(?!(master|model|dbccdb|sybsecurity|sybsystemdb|sybsyste +mprocs|tempdb|DBA)$)(^[a-z0-9_]+$)/i) { print "allowed\n" } else { print "not allowed\n" }
|
|---|