title: IO::Handle to get and unget unicode characters
body: <p>I think I've run into a problem with Unicode and IO::Handle. It's very likely I'm doing something wrong. I want to get and unget individual unicode characters (not bytes) from an IO::Handle. But I'm getting a surprising error.</p>
  
  <pre><code>#!/usr/local/bin/perl
  
  use 5.016;
  use utf8;
  use strict;
  use warnings;
  
  binmode(STDIN,  ':encoding(utf-8)');
  binmode(STDOUT, ':encoding(utf-8)');
  binmode(STDERR, ':encoding(utf-8)');
  
  my $string = qq[a Å];
  my $fh = IO::File-&gt;new();
  
  $fh-&gt;open(\$string, '&lt;:encoding(UTF-8)');
  
  say $fh-&gt;getc(); # a
  say $fh-&gt;getc(); # SPACE
  say $fh-&gt;getc(); # Å LATIN CAPITAL LETTER A WITH RING ABOVE (U+00C5)
  $fh-&gt;ungetc(ord("Å"));
  say $fh-&gt;getc(); # should be A RING again.
  </code></pre>
  
  <p>The error message from the ungetc() line is "Malformed UTF-8 character (unexpected end of string) in say at unicode.pl line 21. "<code>\x{00c5}</code>" does not map to utf8 at unicode.pl line 21." But that's the correct hex for the character, and it should map to the character.</p>
  
  <p>I used a hex editor to make sure that the bytes for A-RING are correct for UTF-8.</p>
  
  <p>This seems to be a problem for any two-byte character.</p>
  
  <p>The final say outputs '\xC5' (literally four characters: backslash, x, C, 5).</p>
  
  <p>And I've tested this by reading from files instead of scalar variables. The result is the same.</p>
  
  <p>This is perl 5, version 16, subversion 2 (v5.16.2) built for darwin-2level</p>
  
  <p>And the script is saved in UTF-8. That was the first thing I checked.</p>