With Python - I can take a string and return it with multibyte characters UTF-8 escaped:
$ python3 -c 'print("hello ☺ world".encode("utf-8"))'
b'hello \xe2\x98\xba world'
Or unicode escaped:
$ python3 -c 'print("hello ☺ world".encode("unicode-escape"))'
b'hello \\u263a world'
Can Perl do something like this? I tried "quotemeta" but it seems it is not the right tool:
$ perl -e 'print quotemeta("hello ☺ world\n");'
hello\ \�\�\�\ world\