The funniest part is that all three for-loops (parent, this, and child) are wrong (which only is a great defense of the whole point). The correct versions are
for (my $i = 0; $i <= $#names; $i++) { ... }
# or
for (my $i = 0; $i < @names; $i++) { ... }