use PerlIO::gzip; open( my $fh , ">:gzip", "file.txt.gz") || die $!; print $fh "hello!\n"; close($fh); open( my $fh2 , "<:gzip", "file.txt.gz") || die $!; print <$fh2>; close($fh2);