my $cmd="ls /no/way"; my @data=`$cmd`; if($?) { print "$cmd failed with exit code $?\n"; exit 1 } foreach (@data) { chomp; my @ret=split; # do something with @ret here ? }