#!/usr/bin/perl -w $| = 1; use strict; use Unicode::String qw(latin1 utf8); my $foo = $ARGV[0] || ''; $foo = &toISO($foo); print "-> $ARGV[0]\n"; print "<- $foo\n"; sub toISO($) { my $text = $_[0]; # if this host was UTF-8 encoded: my $text_iso = (utf8($text))->latin1; my $text_utf8 = (latin1($text_iso))->utf8; # reverse check if ($text ne $text_utf8) { # print STDERR "Unequal reverse check! It seems your input data \"$text\" is ", # "ISO encoded already, so you don't need the latin1 encoding stuff here!\n"; # I'm going to fix this $text_iso = $text; } $text_iso; }