use Parallel::ForkManager; $pm = Parallel::ForkManager->new(2); foreach my $input_file (@files) { my $pid = $pm->start and next; system("shell_script < $input_file"); $pm->finish; # Terminates the child process }