|XP is just a number|
tilly mentions XP in passing. I've learned quite a bit from that approach.
Two things come to mind.
First, write unit tests. jlp just wrote a very small and clever module for Jellybean that makes running tests very easy. If you have more complex needs, clemburg works on the Test-Unit bundle on the CPAN. Having a comprehensive test suite will prove baseline functionality, freeing you to clean things up inside without having to wonder if your changes broke something. (It's not 100% guaranteed, but if you move things around and a test suddenly fails, you know exactly why.)
The second thing is to keep your design as simple as it needs to be. That doesn't mean you design everything at the start and stick with that until the bitter end. It doesn't mean that you find yourself in a corner and rewrite everything. It means that you add features only when absolutely necessary. After you add a feature and its tests pass, go back over the code and see if you can simplify it further. The tests will tell you if you break something.
This all presupposes that you're a competent enough programmer to have good habits from the start -- you are. If you weren't, you wouldn't have recognized this and you wouldn't be asking for advice. Trust your instincts, but cultivate good habits to keep you from false Laziness.
Finally, when you're stuck, look at the project and ask yourself, "What needs to be done?" Organize that list according to importance. Then break the most important thing into individual units that can be added, tested, and debugged in a single sitting. Then do it.
If you can follow this half of the time, you'll be twice the programmer in short order. The tests are the key.