use PerlIO::gzip; open my $in, '<:gzip', 'foo.txt.gz' or die $!; while (<$in>) { #etc; }