use strict; use warnings; my $thr; # ... sub manager() { local $| = 1; while (print '.') { opendir(my $dir_handle, './acc'); FILE: while (my $file = readdir($dir_handle) ) { # or use /.dat/ if that's what you meant next FILE if $file !~ /[.]dat$/; open(my $reader, '<', "./acc/$file"); my @items = <$reader>; close($reader); $thr = threads->new(\&initiator, @items); unlink("./acc/$file"); } close($dir_handle); sleep(2); } }