$_ = "This line contains 0xC30x86n exotic character."; s/0x([0-9a-fA-F]{2})/chr(hex($1))/eg; utf8::decode($_); #### use HTML::Entities qw( encode_entities ); open(my $fh, '>:encoding(UTF-8)', 'file.html') or die; print $fh qq{\n}; print $fh qq{Test\n}; print $fh encode_entities($_); # Escapes &<>'" #### 3C 6D 65 74 61 20 68 74-74 70 2D 65 71 75 69 76 ..Test 3C 2F 74 69 74 6C 65 3E-0D 0A 54 68 69 73 20 6C ..This l 69 6E 65 20 63 6F 6E 74-61 69 6E 73 20 26 41 45 ine contains &AE 6C 69 67 3B 6E 20 65 78-6F 74 69 63 20 63 68 61 lig;n exotic cha 72 61 63 74 65 72 2E racter.