Count the number of substring occurrences