my ($thr, $total_count); sub create_file { my $count = shift; open(FH, ">$count"); close(FH); return $count; } foreach my $count (1 .. 5) { $thr = threads->create(\&create_file, $count); } foreach my $t (threads->list()) { $ret = $t->join; $total_count += 1; } print "Total count : $total_count \n";