use strict; use warnings; my $str = "\tthis is a sample string\nwith various white space characters\n"; my $str2 = $str; $str2 =~ tr/\t \n/\0\1\2/; $str2 =~ s/([\0\1\2])/('\t', '\s', "\\n\n")[ord($1)]/ge; print $str."\n"; print $str2;