in reply to Strip filename

$ans =~ y/[[:space:][:cntrl:]]//d;

As the docs say (--> 'Note that "tr" does not do regular expression character classes such as "\d" or "[:lower:]"'), character classes cannot be used with tr/// (which is the same as y///).  Use regex substitution (s///) instead.