in reply to Refactor huge subroutine
Some <readmore> tags would be good for that big block of code.
I haven't looked too deeply at what this is doing, but one strategy I've heard of for this kind of situation is to turn it into an object (maybe several). You make the long-lived variables into attributes to save yourself from passing them in and out everywhere. Then you can start cutting things up into smaller and smaller routines.