After some attempts at a solution at the limit I went back to the Wikipedia page on the divisor function.
Implemented a priority queue for the first time, unfortunately the plethora of modules implementing this in Perl made it hard to choose. Finally went for the POE framework.