11.3. Making Things Better
Here we discuss a few ways of improving your program's use of resources. You'll find terse descriptions of many more in Programming Perl (Chapter 8 in the second edition, Chapter 24 in the third).
11.3.1. Improving Execution Speed
It is common for improvements in execution speed to cost dearly in the readability department. Adding lookup caches, rearranging statement order, and inlining subroutine calls conspire to make a program less maintainable; therefore, as we have said before, you do these things only when you have to.
Once you've identified the code that is taking the most time, the next step is to optimize that code. A few suggestions follow.
Inside a loop, take every opportunity to get out of it as early as ...