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 $_; }