~~~ Human readable output of what is being generated ~~~~~~~~~~~~ Line1 Line2 Line4 ~~~~~ Actual Results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4C 00 69 00 6E 00 65 00 31 00 0D 0A 00 4C 00 69 00 6E 00 65 00 32 00 0D 0A 00 0D 0A 00 4C 00 69 00 6E 00 65 00 34 00 0D 0A 00 ~~What was expected and is required for valid UTF-16LE encoding ~~~ 4C 00 69 00 6E 00 65 00 31 00 0D 00 0A 00 ^ byte missing from actual results 4C 00 69 00 6E 00 65 00 32 00 0D 00 0A 00 0D 00 0A 00 ^ byte missing from actual results ^ byte missing from actual results 4C 00 69 00 6E 00 65 00 34 00 0D 00 0A 00 ^ byte missing from actual results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #### use strict; use warnings; use Encode qw(encode decode); ### Actual Results my $string = "Line1\nLine2\n\nLine4\n"; open (my $output_fh, ">:encoding(utf-16le)", 'Test_reg.reg') || die "Unable to create reg output file. $!"; print {$output_fh} $string ; ### something else I tried, also doesn't work correctly. my $string2 = "Line1\015\012Line2\015\012\015\012Line4\015\012"; open (my $output_fh2, ">:encoding(utf-16le)", 'Test_reg2.reg') || die "Unable to create reg output file. $!"; print {$output_fh2} $string2 ;