a couple things of note is that
/(\w{2,16})/ will not check to see if the
$username is between 3 and 16 letters and numbers. The fact that the lower limit is 2 will allow anything that is at least 2 characters. Also the fact that you have 16 in there doesn't do much more than tell the regex not to match more than 16
\w chars in a row. To put it another way it will match the most left hand match that is at least 2 characters long (in the character class
[A-Za-z0-9_]) and will then try to match up to 16 characters (and this will be stashed into
$1) Which might not be what you want as then anything over 16 characters will be truncated off when you replace the value in
$username with
$1. And as I already mentioned
\w will match letters number and underscore (which does not fit your criteria) You might be looking for something more along these lines.
...
if ( $username =~ /\A([A-Z0-9]{3,16})\z/i ) {
$username = lc($1);
}
else { ... }
Lastly if you are not going to capture what is output by the command you should use
system instead of backticks (though you should probably capture what is returned by system anyhow) .
Note: that
$username will have to be chomped (have the newline removed) or
\z won't match, in which case changing
\z for
$ will do just as well.
One last thing is that you should really go through perlre and perlretut as they contain invaluable information.
-enlil