use Encode qw( encode ); # Or whatever encoding you specified in $xmldata = encode('UTF-8', $xmldata); my $length = length( $xmldata );