in reply to How to write long programms?
There's some very good advice above, with one caveat: we're not inside of your head, so we can only guess at why it is that you're having difficulties understanding your own code.
Solving this is going to require some introspection on your part. You're going to need to take a step that may be difficult: Each time you find yourself not understanding your code, step back for a moment and try to get more specific about what you're not understanding. Are you lost in the the structure? Are you lost trying to figure out what your regular expressions are doing? Are you lost trying to tell where things happen in your code? Are you lost trying to figure out why things happen in your code?
Once you've labeled a particular problem, a good step is to consider what you could have done up front (2 days earlier) to avoid that problem. This may using clearer variable names, or whitespace around certain syntactic elements, or more (or less) commentary. Without seeing your code through your eyes, it's hard for us to guess what you'll need to do.
The next step is an important one: Write your observations down. Keep a log. With a written record, you're more liable to see repeated patterns that you miss in day-to-day coding and debugging. And the mere act of writing problems down can be a creative stimulation.
You may find that you only need the log for a while. But if you start working on larger projects you'll run into a different class of problems, and you might want to start keeping a log again. A 250 line CGI script might seem large now, but one day you might find yourself working inside of a 250,000 line system.