my $string = "abc12defghi\013jkl"; (my $copy = $string) =~ s/([^[:print:]])/sprintf " (0x%02x) ", ord $1/ge; print $copy;