# $data is a hashref, a standin for the data struct you have my @ranks = \(grep {defined} values %$data); my $idx = 0; $$_ = ++$idx for sort {$$a <=> $$b} @ranks; # step 1 & 2 $$_ /= $idx for @ranks; # step 3