open CMD, '-|', 'ls -l' or die $!; while( my $fname = ) { chomp $fname; #process the file names one at a time } close CMD;