for my $idx (0..$#dirnames) { ... fork ... say $dirnames[$idx]; ... }