Use substr_compare() instead of actually creating substrings
Before: Time taken: 1.971 seconds
After:  Time taken: 1.883 seconds