The first part before the first dot "." in $explodedFileName[0] should not be compared against this negative list. Or should be removed from the array before the foreach (and the >2 changed to >=2).