Sometimes it is good just to work out the steps of your program in different subroutines. It makes it very understandable and clear.
E.g. i am sleepy now, so
# i don't go into details about the subs now :-)
Sometimes it is very useful to store your reusable routines in separate files, in a common directory, and include them in your script, but be careful, too much include files messes up everything. Be smart. :-)