use strict; use warnings; my $data = do { local $/; lc }; my @words = $data =~ /\w+/g; { no warnings; sub cmpix { for (my $off = 0;; $off++) { my $cmp = $words[$a+$off] cmp $words[$b+$off]; return $cmp if $cmp; } } } my @ixs = sort cmpix 0..$#words; # replace this code with duplication detector (it # should be easy!): for my $ix (@ixs) { print substr(join(" ", @words[$ix..$#words]), 0, 50), "\n"; } __DATA__ ...