Refactor script for sorting perl files for O'Reilly books