use IO::Uncompress::Gunzip qw(gunzip $GunzipError); $input="file.dat.gz"; $output="file.dat"; if (-e $input) { gunzip $input => $output or die "gunzip failed: $GunzipError for $output\n"; }