use Encode qw( encode ); print($fh encode("UTF-8", $text));