Some words of wisdom from Dan Sugalski on PerlMonks ...
- If you're going to do something more than twice, make it a function
- If you're going to use it in more than two programs, make it a module
- If doing it even once made your head hurt, throw it in a module
- If it has data you don't want to change yourself, make it work from template files
- If the code is could be generated from some sort of parameters, use a templating code generator for it
- If it feels like a monkey could do it, check the above list to see what you missed