Well I think you are getting into premature optimization. I would focus on cleaning up your code and making it more maintable before you look at speeding it up.

Right off the bat your (lack of) indenting makes it almost impossible to follow your code (Thanks emacs and perl-mode).

If you had warnings turned on you would see that you are using single element array slices (bad ju-ju). You are not using strict.

You break some (IMO) important idioms. Particularly using upper case for filehandles (DICT). This would also turn off some bareword warnings. Use $_. It makes your code more readable, sort of like pronouns.

Please do not mix you main program logic with your subroutines. This makes it very hard to follow.

You should also pass you vars into subroutines and avoid using globals in your subs.
sub word { my $word; foreach $word ( @{ $wordpl{$l} } ) { my $oword=$word; #define original word my $p=$l-1; word1($p, $word); } }
Here $l and %wordpl are in the main package not passed into your sub.

I would also recommend reading perlstyle. It goes into more detail than I willing to go into in this post.

As a final note - these suggestions not only help you debug your code, but it helps other PM's read your code so they can offer better advice.

grep
grep> chown linux:users /world

In reply to Re: Add-A-Gram Performance by grep
in thread Add-A-Gram Performance by smgfc

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.