in reply to Re^2: Strip filename
in thread Strip filename

Is there any alternative for this

Yes:  $ans =~ s/[[:space:][:cntrl:]]//g;