open my $out_fh, ">:encoding(UTF-8)", $opt->{out} or croak "Can't open file $opt->{out}!"; ... nstore_fd $data, $out_fh; ... close $out_fh;