title: using perl tie::file with utf encoded file
body: <p>Can I use <code>Tie::File</code> with an output file of utf encoding? I can't get this to work right.
  What I am trying to do is open this utf encoded file, remove the match string from the file and rename the file.</p>
  
  <p>Code: </p>
  
  <pre><code>use strict;
  use warnings;
  use Tie::File;
  use File::Copy;
  
  my ($input_file) = qw (test.txt);
  
  open my $infh, "&lt;:encoding(UTF-16LE)", $input_file or die "cannot open '$input_file': $!";
  
  for (&lt;$infh&gt;) {
      tie my @lines, "Tie::File", $_;
      shift @lines if $lines[0] =~ m/MyHeader/;
      untie @lines;
      my ($name) = /^(.*).csv/i;
      move($_, $name . ".dat");
  }
  
  close $infh
      or die "Cannot close '$input_file': $!";
  </code></pre>
  
  <p>Code: (updated)</p>
  
  <pre><code>my ($input_file) = qw (test.txt);
  my $qfn_in = $input_file;
  my $qfn_out = $qfn_in . ".dat";
  
  open(my $fh_in, "&lt;:raw:perlio:encoding(UTF-16le):crlf:utf8", $qfn_in)
     or die("Can't open \"$qfn_in\": $!\n");
  
  open(my $fh_out, "&gt;:raw:perlio:encoding(UTF-16le):crlf:utf8", $qfn_out)
     or die("Can't open \"$qfn_out\": $!\n");
  
  while (&lt;$fh_in&gt;) {
     next if $. == 1 &amp;&amp; /MyHeader/; 
     print($fh_out $_)
        or die("Can't write to \"$qfn_out\": $!");
  }
  
  close($fh_in);
  close($fh_out) or die("Can't write to \"$qfn_out\": $!");
  
  rename($qfn_out, $qfn_in)
     or die("Can't rename: $!\n");
  </code></pre>