in reply to IO::Compress::Gzip and unicode

You can use PerlIO layers to do that.

PerlIO::via::gzip provides on the fly data compression (and it uses IO::Compress::Gzip under the hood).

# untested! sub writefile { my($opts) = @_; open my $fh, '>', $opts->{filename} or die $!; binmode($fh, ':via(gzip)') if $opts->{'gzip'}; binmode($fh, ':utf8'); print $fh $opts->{'data'}; $fh->close; }