I know this thread is pretty old, but I just read it and saw a way to improve the code. One thing you could do that should speed things up is to store the results in a hash. You can then avoid using uniq and you will only be doing the matching operation on pieces you haven't yet seen.
#!/usr/bin/perl -w use strict; my $line; my %count; while ( defined ( $line = <> ) ) { chomp $line; for my $a ( 1 .. length ( $line ) ) { for my $b ( 1 .. ( length ( $line ) + 1 - $a ) ) { my $out = substr ( $line, $a - 1, $b ); next unless $count{ $out }; # so you don't have to use uniq next if ( $count{ $out } = () = $line =~ /$out/g ) > 1; print "length: $b digits: $out quantity: $count{ $out }"; } } }
I just glanced through the other comments and saw some good points in there too, so if you're using this code make sure to take those into account as well. I didn't want to rewrite the whole thing, but just wanted to point out how the hash could be useful.

In reply to Re: Longest repeated string... by redEvo
in thread Longest repeated string... by Yzzyx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.