use PerlIO::encoding; # Modify a copy of a file... sub foo { my $thing_to_do_ref = shift; my @lines; if (open IN, "<", "$some_path") { binmode IN, ":encoding(UTF-16LE)"; while ( my $a_line = ) { # Do stuff to $a_line... } push @lines, $a_line; } close IN; if (open OUT, ">", "$some_other_path") { binmode OUT, ":encoding(UTF-16LE)"; while (@lines) { my $line = shift @lines; print OUT "$line\n"; } close OUT; } else { print "Oops! Could not write: $! \n"; } } else { print "Oops! Could not read: $! \n"; } }