in reply to
This is not a perl solution and doesn't offer source code but if you're keen on saving time and not re-inventing the wheel, you can check out:
They have an e-Commerce shipping calculator that packages items into multiple boxes of different sizes and returns the postage. It also supports items with multiple packaging dimensions or "this-side-up" restriction, and boxes with postage varied by weight. There is an online API for integration with any application. As long your app has Internet connectivity, you can add to it.