use strict; use warnings; use List::Util qw/shuffle/; use Data::Dumper; my ( @array, %histRand ); my %hist = ( apples => 4, oranges => 19, pairs => 10, peaches => 5 ); push @array, ($_) x $hist{$_} for keys %hist; @array = shuffle @array; $histRand{ $array[ rand $#array + 1 ] }++ for 0 .. $#array; print Dumper \%histRand;