Michael Schwern has a new article on perl.com about refactoring. It's a great example to learn from. Michael ended up at something quite different from what I'd have written. I'm not sure if it's better or not but it's certainly a different way to solve the problem.