I had taken a chance of reading the weblink that you wrote but after 30 seconds I gave up... so I will try to give only general advices here.

First of all, don't do this:

$ ./test < textfile | sort | uniq

Perl has more then enough tools to do the job that is done with sort and uniq programs. System calls are expensive and sometimes the speed of those programs doesn't pay for the cost of invoking them.

To read the file, use open function. If the file is not that big, you can read it entirely and put into memory like this:

open(IN,"<$file") or die "Cannot read $file: $!\n"; my @content = <IN>; close(IN);

This will speed up things than using while block.

Use an array to keep the results from the string:

$results[0]++ if ( $digit == 0 );

You can even avoid using if statement to do that. For the next string to process, do a @results = () to start again with zeros.

Try as much as you can to avoid using next loops with for. Look for the Schwartzian Transform to see how to improve your code. Try using @sequence = split( //, $sequence ) instead of a other loop.

And last but not least, check the Benchmark module to test all those things.

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

In reply to Re: Longest repeated string... by glasswalk3r
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":