use warnings; use strict; my $infile = 'D:/try_unicode/input.txt'; # or whatever my $outfile = 'D:/try_unicode/output.doc'; open my $input, '<:utf8', $infile or die "Couldn't open file: $!"; open my $output, '>:utf8', $outfile or die "Couldn't open file: $!"; while (my $line = <$input>) { chomp $line; print $output 'The first four utf-8 chars from the line: ', pack( "U4", unpack( "U4", $line ) ),"\n"; print $output 'Or, an easier way to get the same thing: ', substr $line, 0, 4; print $output "\n", '-' x 79, "\n"; }