What have you tried? The following works for me:
use strict;
use warnings;
open(my $fh_in, '<:raw:encoding(utf16le)', 'src.txt')
or die("Unable to open src.txt: $!\n");
open(my $fh_out, '>:raw:encoding(utf16le)', 'dst.txt')
or die("Unable to create file.txt: $!\n");
while (<$fh_in>) {
if (/[\x{706B}\x{6C34}]/) {
print("Found one at line $.!\n");
}
print $fh_out $_;
}
The :raw prevents the CRLF->LF conversion when reading and the LF->CRLF when writting. The conversion only works with single-byte, ASCII-based (i.e. LF=0xA, CR=0xD) encodings.
Use :raw:encoding(utf16le) if the file was saved using encoding "Unicode"
Use :raw:encoding(utf16be) if the file was saved using encoding "Unicode big endian"
Use :raw:utf8 if the file was saved using encoding "UTF-8"
Update: Added example regexp to code.
|