my %ws = ( "\x09" => qw( \t ), "\x0A" => qw( \n ), "\x0C" => qw( \f ), "\x0D" => qw( \r ), "\x20" => qw( \s ), ); while (<>) { s/(\s)/$ws{$1}/g; print; print "\n"; # keep it line for line. } #### perl -pe 's/(\s)/sprintf"\\x%02x",ord$1/ge;$_.=$/'