in reply to Expression, but is it regular?
You're probably looking for something like that:
my $dirtype = $in{username} =~ /^([a-zA-Z]{2})$/ ? $1 : 'other' ;