use File::Basename;
my $mailfile = "$ENV{'HOME'}/mail/mbox";
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
open(my $out, ">>:utf8", $mailfile) || die "$mailfile: $!";
while (<>) {
print $out "\n";
close($out);
1;
</pre>