#!/usr/bin/perl -w $| = 1; use strict; use Unicode::String qw(latin1 utf8); my $foo = $ARGV[0] || ''; if (&isISO($foo)) { print "Is ISO!\n"; $foo = (latin1($foo))->utf8; } else { print "Is UTF\n"; } print "-> $ARGV[0]\n"; print "<- $foo\n"; sub isISO ($) { my $text = $_[0]; my $text_iso = (utf8($text))->latin1; my $text_utf8 = (latin1($text_iso))->utf8; # reverse check return $text eq $text_utf8 ? 0 : 1; }