Assuming that
Athanasius's comment will solve your issue, I would just further comment that you should probably consider using one or two array(s) of directories rather than having all these $dir1, $dir2, ..., $dirs, $dirt, etc. variables.
And of course, I agree that you should most probably avoid the function call with a leading ampersand.