$pid = open (INPUT, "mycommand $somefile |") or die ...; while () { if ( ... trigger to stop ... ) { kill 9, $pid; last; } } close INPUT; #### $pid = open (INPUT, "gzip -dc $somegzfile | mycommand |") or die ...; while () { if ( ... trigger to stop ... ) { kill 9, $pid; last; } } close INPUT;