http://www.perlmonks.org?node_id=817283


in reply to Modified Binary Search

Build a new array containing the indexes of the elements where sequences of equal strings start. For instance:
@a = qw(a a b b c c c d e e e e e f f) # ix: 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 #start: * - * - * - - * * - - - - * - @start = (0, 2, 4, 7, 8, 13);
Then just perform the binary over @start, using $a[$start[$ix]] as the search key.

Once you find the index $ix corresponding to the searched element, the start and end offsets will be $start[$ix] and $start[$ix+1] - 1