#!/usr/bin/perl use strict; use warnings; use locale; use utf8; use Encode; binmode STDIN, ":utf8"; binmode STDOUT, ":utf8"; # test non-default output too open(OUT, ">utf8", "sample_out.txt"); print "Command line argument: \n"; my $t = $ARGV[0]; &output_string($t, decode("utf-8", $t)); print "Enter some umlaut, please: "; $t = ; # õäöüšž is good input to test chomp($t); &output_string($t); print "Variable from source code: \n"; $t = "õäöüšž"; &output_string($t); print "String from file: \n"; open(IN, "; close(IN); chomp($t); &output_string($t); close(OUT); sub output_string { my ($str) = shift; my ($dstr) = shift || ''; my ($ustr) = uc($str); print length($str), " $str $ustr $dstr\n\n"; print OUT "$str $ustr $dstr\n"; } __END__ sample.txt contains the same string: õäöüšž