in reply to help needed in encoding

Propably you exchanged the parameters of encode?
print $encoding ? encode($encoding, $string) : $string;
Boris