Well, I only use STDIN to get user input, which is always just one line, which I store in a variable and then use it for whatever purpose later... So I don't see how a while loop would be useful.
Anyway, the more I know about this stuff, the less I understand it.
I tried just adding
binmode STDIN, ':encoding(UTF-8)';
to the script above, now I get a different problem: error messages of this sort:
utf8 "\xFB" does not map to Unicode at [script] line 8.
The output file contains the character codes instead of the characters:
\xFB\x{32CB8E1}\x82\xA0
Maybe I should be using encode() and decode() but I just don't know how they relate to "use utf8", and "binmode :encoding(UTF-8)". This is a huge mess and I feel like I'm having to fight a hundred dragons just to get some damned characters to display correctly. Why everything isn't in UTF-8 in the first place is beyond me, it's 2010 for God's sake!
Anyway, I ran the test from your link ( http://perlgeek.de/en/article/encodings-and-unicode ) as well. The results are not good: all 4 lines are mojibake. The dragons are clearly winning.