foreach my $file (@files) { ... forking goes here ... while (wait () != -1) { ... check $? ... } }