use strict; use warnings; inspect("abcd\n123"); sub inspect { (my $copy = shift) =~ s/([^[:print:]])/sprintf " (0x%02x) ", ord $1/ge; print $copy; }