print ":$_:", ord($_), "\n" for (split //, $str) #### my $copy = $str; $str =~ s/([^\x20-\x7E])/sprintf '\x{%02x}', ord $1/eg; print $str, "\n";