#! perl use strict; use threads ( 'yield', 'stack_size' => 64*4096, 'exit' => 'threads_only', 'stringify' ); my $path = "/tmp"; my @files = &get_files($path); my @thrs_loaders; foreach my $file (@files){ push @thrs_loaders, threads->create(\&load, $file); } $_->join for @thrs_loaders; <>; exit; sub get_files{ my $dir = shift; opendir(my $dh, $dir) or die "Cant open dir $!"; # HERE IS THE CAUSE close( $dh); return "detail-1min-19-06-22"; } sub load{ my $file = shift; print "Processing $file\n"; }