in reply to Poorly written script
Twice you create a list @allfiles only to get its length. You could get the same functionality by iterating through in stead of the grep -T, map .... This would take the space of 1 integer (for the running count) in stead of an entire array.