package MyClass; use Moose; use Moose::Util::TypeConstraints; subtype 'StringWithDashes' => as 'Str' => where { /^[\w-]+$/ }; has 'fname' => ( is => 'rw', isa => 'StringWithDashes' ); has 'lname' => ( is => 'rw', isa => 'StringWithDashes' );