my $str="17:43:33:21:23:19:27:6"; my %hash = split /:/, $str; my $adno; my $rand = rand 100; my $sum = 0; for (keys %hash) { # there is no need of sorted keys $adno = $hash{$_}; last if ($sum += $_) > $rand; } print $adno;