#! perl -slw use strict; use List::Util qw[ sum ]; use threads; sub joinable { threads->list( threads::joinable ) }; sub running { threads->list( threads::running ) }; my @files = map glob, @ARGV; our $T //= 4; my @results; for my $file ( @files ) { async { return `wc -l "$file"`; }; next if running() < 4; push @results, $_->join =~ m[(\d+)] for joinable; sleep 1 while running >= 4; } sleep 1 while running; push @results, $_->join =~ m[(\d+)] for joinable; print "The average number of lines in all the files is:", sum( @results ) / @results; __END__ C:\test>996731 a*.* The average number of lines in all the files is:77346.75