open( CMD, "$command |" ) or die "Cannot open $command: $!\n"; while ( defined( my $line = ) ) { # Do stuff with $line which is the output from $command } close CMD;