eval "\$_ = decode('utf8',\$orig_data,Encode::FB_CROAK)"; if ($@) { # it's not utf8, and so must be iso-8859-1 }