perl -Mutf8 -lwe '$foo=chr(300);utf8::encode($foo) if utf8::is_utf8($foo);print $foo'