This is slightly off-topic, but just for your information, there is a description of the heap algorithm in the book
Mastering Algorithms with Perl (O'Reilly, by Jon Orwant, Jarkko Hietaniemi, and John Macdonald). I think that the authors wrote a module (probably aimed at pedagogical purposes more than production) going with the book; but I'm not at home and can't check the book's content today, and I don't know if that particular algorithm is in this module.
My book on Perl 6 also has something on heaps, but this is getting even more OT.