#! perl -slw use strict; for( qw[ ab123 'ab123s 'ab123's ] ) { if( m[ ^'? [a-z] ## start with letter or an apostrophy followed by one [a-z0-9'-_]+ ## Alphanumeric + '-_ (?: [a-z0-9] | s') $ ## ends with alphanumeric or s' ]x and not m[''|--] ## No doubled ''s or --s ){ print "$_: Ok!"; } else { print "$_: Bad!"; } } __END__ C:\test>junk ab123: Ok! 'ab123s: Ok! 'ab123's: Ok!