Thank you again, :raw:encoding(UTF-16LE) didn't help. This produces 00 0A 00 as newline. It looks like correct Unicode but not same as need. Here is the output of a different setting using the PerlIO::get_layers($fh):
layers :raw:encoding(UTF-16LE):crlf:via(File::BOM): unixencoding(UTF-16LE)utf8crlfutf8viautf8 layers :encoding(UTF-16LE): unixcrlfencoding(UTF-16LE)utf8 :raw:encoding(UTF-16LE): unixencoding(UTF-16LE)utf8
I found the solution in the activestate forum: http://community.activestate.com/forum-topic/creating-unicode-utf-16le. You need to use File::BOM and open the file as following:
open my $fh, '>:raw:encoding(UTF-16LE):crlf:via(File::BOM)', 'file.reg +';
The same problem is described there. I don't know what this line is doing, any comments of unicode and Perl insiders are welcome. I assume this writes newline using this File::BOM module and this way the byte order is correct. My script is now writing pretty fine output. I exported the whole HKLM/Software and had only few differences. This is a value I can live with. If I export only the sub-tree of my interest the file is completely identical to the output of regedit.exe. Thank you for your help.

In reply to Re^5: Win32 registry export by wwe
in thread Win32 registry export by wwe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.