Refactoring string.startswith() to handle multiple matches more efficiently