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 ;