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++ 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.
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>