use strict; use warnings; open my $PL, '>', 'utf2.pl' or die $!; print {$PL} << '__PL__'; ########################################################## use strict; use warnings; binmode STDOUT, ':utf8'; binmode STDIN, ':utf8'; while (my $line = <>) { if (my ($word) = $line =~ /^(.+)$/) { my $one = substr($1, 0, 1); # doesn't work my $w_one = substr($word, 0, 1); # works print "'$one' = '$w_one'\tat $line" unless $one eq $w_one; } } ########################################################## __PL__ open my $OUT1, '>', 'utf1' or die $!; print {$OUT1} map chr hex, qw/61 61 c5 99 0a c4 8d 0a 61 61 c5 99 0a/; close $OUT1; open my $OUT2, '>', 'utf2' or die $!; print {$OUT2} map chr hex, qw/c4 8d 0a 61 61 c5 99 0a c4 8d 0a/; close $OUT2; system "$^X utf2.pl < utf1"; print "\n"; system "$^X utf2.pl < utf2";