I would like to encode 'special chars' to their named entity.
Perl doesn't know the encoding of your source file. If you include any special characters, you should always save it with
UTF-8-encoding and put
at the top of your code. This will make sure your string literals contain codepoints, not just bytes.