Setting "$|" to "1" at the very beginning of the script didn't help. However, it fixed some characters but broke other characters. So it makes difference.

If I run the same CGI request multiple times, I get same broken characters at same places, i.e. same stream.

I have reviewed the stream with hex editor. It starts with "FF FE".

Here is something interesting.
  Г л а в н а я              
Normal: 00 13 04 3B 04 30 04 32 04 3D 04 30 04 4F             
Broken: 00 13 04 3B 04 30 04 32 04 5C 00 78 00 44 00 30 00 5C 00 78 00 42 00 44 00 3004 4F
  Г л а в \ x D 0 \ x B D а я

I really can not explain this.


In reply to Re^6: UTF-8 problem, some chars appear as \x.. by zanzibar
in thread UTF-8 problem, some chars appear as \x.. by zanzibar

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.