in reply to Removing Bad Characters from a String

$bad_chars = qr{[!~?/@]}; # remove any potential bad characters $filename =~ s/$bad_chars//g;
You might want to read perldoc perlre for more.