Brute-force substring match algorithm