my @files = @ARGV; my $NUM_CPUS = 4; # or whatever my $jobs = Thread::Queue->new(@files); # We use undef as "end of jobs" marker $jobs->enqueue( undef ) for $NUM_CPUS; my @threads = map { threads->create(\&process); } 1..$NUM_CPUS; sub process { while( my $file = $jobs->dequeue ) { validate_the_file($file,$readOnlySchema); }; }; $_->join for @threads;