in reply to build a distribution

May I suggest Math::GSL in particular the Histogram module. Seems like stuff that you want
http://search.cpan.org/~leto/Math-GSL-0.22/lib/Math/GSL/Histogram.pm