in reply to How do I keep anything other than alphanumeric out of a variable?

As long as you are willing to concede that an underscore '_' is alphanumeric, you can use this:

$user_name =~ s/\W//g;
\w is shorthand for the character class [A-Za-z0-9_] and \W is the inverse of that set, i.e. [^\w].