use IO::Uncompress::Gunzip qw( $GunzipError ); my $file = "somefile"; my $gz = new IO::Uncompress::Gunzip $file or die "Cannot open $file: $GunzipError\n" ; while (<$gz>) { # whatever... }