use Modern::Perl '2015'; use Encode qw( encode decode ); #use utf8; my $encoding = $^O eq 'MSWin32' ? 'cp1252' : 'utf8'; #$encoding = 'Windows-1252'; #$encoding = 'cp1252'; #$encoding = 'utf8'; say "Encoding: $encoding <"; binmode(STDOUT, ":encoding($encoding)" ); binmode(STDERR, ":encoding($encoding)" ); binmode(STDIN, ":encoding($encoding)" ); # each open() automatically uses :encoding($encoding) use open ':encoding($encoding)'; my $res_file = "erg_1252.txt"; open(my $fh, ">:encoding($encoding)", $res_file) or die "Could not open file '$res_file'"; my $eur = decode("$encoding", "€"); my $uml = decode("$encoding", "äöüßÄÖÜ"); say $fh "Umlaute: äöüßÄÖÜ"; say $fh "Euro: €"; say $fh "decodiert"; say $fh "Uml: $uml"; say $fh "Eur: $eur"; say "\nNicht decodiert"; say "Umlaute: äöüßÄÖÜ"; say "Euro: €"; say "\ndecodiert"; say "Uml: $uml"; say "Eur: $eur"; close $fh;