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