my $foo = "A string to work on."; my @substrs = map {\substr $foo, $_} 0 .. length($foo) - 1; my @sorted = sort { $$a cmp $$b } @substrs;