in reply to unix file permissions? or perhaps something that will make me look silly...

If this is an accurate copy-and-paste, you're replacing rather than adding to $totalfiles: my $totalfiles =+ $numfiles; Should be:    $totalfiles += $numfiles; Also, don't my it in the loop, do it beforehand.

HTH