my $ntext = length $text; my $bwt2 = join('', map{substr($text, ($_ - 1), 1)} sort{ my $j = -1; my $diff = 0; while( $j++<$ntext ) { $diff = substr( $text, ($j+$a) % $ntext, 1 ) cmp substr( $text, ($j+$b) % $ntext, 1 ); last if $diff; } return $diff; } 0..$ntext-1 ); print "$text: $bwt2\n";