# Implementation 1 - the mundane way sub weighted_hash { my $hashref = shift; my @weighted; for my $key (keys %$hashref) { for (1 .. $hashref->{$key}) { push @weighted, $key; } } rand_elt @weighted; } # Implementation 2 - the perl monk one-liner sub weighted_hash { my $hashref = shift; rand_elt map { my $key = $_; map { $key } 1 .. $hashref->{$key} } keys %$hashref; }