use PerlIO::gzip; for (glob '*.gz') { open my $fh, '<:gzip', $_ or die $!; { local $_; while (<$fh>) { # do stuff } } close $fh or die $!; }