#!/usr/bin/perl -w use utf8; # without the encoding layer open (my $fh1, ">", "test-normal"); # with the encoding layer open (my $fh2, ">:utf8", "test-utf8"); # ASCII data # encodes the same in UTF-8 or Latin-1 encodings my $ascdata = "aei\n"; print $fh1 $ascdata; print $fh2 $ascdata; # accented a e i my $l1data = "\xe1\xe9\xed\n"; # these characters *can* be encoded in Latin-1 or in UTF-8 # (though differently for each) print $fh1 $l1data; print $fh2 $l1data; # U+0641 ARABIC LETTER FEH my $u8data = "\x{0641}\n"; # "Arabic-Feh" can't be encoded in Latin-1, can be encoded in UTF-8 print $fh1 $u8data; # <--THIS LINE GENERATES WARNING print $fh2 $u8data;