use warnings; use strict; use Encode qw(encode decode); use Cwd; my $enc = 'UTF-16'; my $dir0 = getcwd; my $file = "x.xml"; open INPUT, "<:encoding($enc)", "$dir0/$file" or die "File $file not found!"; open OUTPUT, ">$dir0/first100_$file" or die "File first100_$file not found!"; open STDERR, ">results_error.log" or die "Can't open log"; my $i = 0; while () { if ( $i < 100 ) { print OUTPUT $_; # (1) # print OUTPUT decode($enc,$_); # (2) # print OUTPUT encode($enc,$_); # (3) $i++; } } close INPUT; close OUTPUT; close STDERR;