#!/usr/bin/perl -w use open qw/:std :encoding(iso-8859-1)/; # default I/O encoding my $s = "A \N{WHITE SMILING FACE} for you\n"; open (FILE, '> fpo'); # in the actual code, may open one of several things, or assign STDOUT to FILE my @layers = PerlIO::get_layers(FILE); print "Layers before binmode: @layers\n"; binmode(FILE, ':encoding(UTF-8)') if 1; # override the default encoding under certain conditions @layers = PerlIO::get_layers(FILE); print "Layers after binmode: @layers\n"; binmode(FILE) if 1; # reset to raw binmode(FILE, ':encoding(UTF-8)') if 1; # add our new encoding @layers = PerlIO::get_layers(FILE); print "Layers after reset: @layers\n"; warn "About to print"; # primitive trace statement print FILE "$s";