my $pool = Thread::Pool::Simple->new( min => 2, # at least 2 workers max => $total_threads, # at most x workers load => 10,# add worker if each worker has 10 jobs queued do => [ \&do_handler ], # job handler for each worker passid => 1, # pass the job id->1st arg to &do_handler lifespan => 10000, # total jobs handled by each worker ); open( FLP, $deeper_file_path ); foreach my $file_path () { $pool->add( $file_path, $filelistEXE_path, $scan_table_name); } $pool->join();