$ cat posix.pl #!/usr/bin/env perl use strict; use warnings; my $str = "ab\x{cc}"; $str =~ s/(\P{PosixPrint})/sprintf("U+%04X", $1)/eg; print "$str\n"; $ ./posix.pl Argument "Ì" isn't numeric in sprintf at ./posix.pl line 6. abU+0000 $