use IO::Pipe; my @command =qw(gzip -cd filename); my $fh = new IO::Pipe; $fh->reader(@command)|| warn "ERROR : Can't read : $!"; while(<$fh>) { #doing some long job here;such as $variable = readline $fh; . . . } undef $fh;#close $fh if ($? != 0) { print "problem in undef or closing:$? with status:$!"; }