... if ( $username =~ /\A([A-Z0-9]{3,16})\z/i ) { $username = lc($1); } else { ... }