open(my $fh, '>:utf8', 'out.xml') || die "Failed to open file"; print $fh $str; close($fh) || die "Failed to close file";