in reply to Grouping Files to Fill DVDs
Packing things onto CD or DVD is a well-worn problem space. There are several modules available that can help you out. My favorite happens to be Algorithm::BinPack, but I may be biased (being the author and whatnot). The algorithm it uses is very simple, and if you can't use the module directly, you should be able to take the pertinent bits out without much of a problem.