Well - I am an intermediate level (perl) programmer and I use a couple of rules of thumb:
- create a sub where you use the same code more than once (that means twice!, or more)
- generalize subs via parameters to avoid having multiple similar subs
- if you have a long (ie >500 line) sequence of "meat & potatoes" code, then it is a good idea to reduce your "main" routine to a 30 line-ish sequence of calls to subs ... this is really a way to self document the code and forces you to limit use of global variables to make the code more re-usable