for my $idx (1..@dirnames) { ... fork ... say $dirnames[$idx - 1]; ... }