use Tie::Gzip; tie *CONTENT, 'Tie::Gzip'; open(\*CONTENT, "<$input") or die "Can't open $input\n"; while(){ ... }