in reply to Encoding problem in perl

Is the if ($@) condition ever triggered? If yes, I guess that the string is already decoded somehow, and must only be encode()d; or it might be in a different encoding than you think it is.

A good way to debug this is to enter a single non-ASCII character into the DB, let's say a U+260E BLACK TELEPHONE, or ☎.

Then you can inspect your strings with

use Data::Dumper; $Data::Dumper::Useqq = 1; $logger->debug(Dumper $string);

As UTF-16LE that's encoded as 0e 26, as UTF-8 it's encoded as e2 98 8e

Armed with that knowledge you check where the character encoding starts to diverge from your expectations.