use Encode; ... my $bytes = encode('utf8', $text); # insert $bytes instead of $text