Brute force approach to substring matching