# ... system('gunzip', "$filename.gz"); open(IN, $filename) or die "unable to open '$filename'"; while () { # process each line } close IN; system('gzip', $filename); # ...