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.

I think all of grep's suggestions are good, but I especially want to second the write tests first suggestion. Ideally, you'd have tests that Devel::Cover says exercises most of what's there.

Good luck.