my @indices = sort {$off = 0; until (substr($string, $a+$off, $step) cmp substr($string, $b, $step)){ $off += $step; } } 0 .. length($string) - 1;