Looking for an algorithm to identify contiguous repeated series of lines in a long string