my @genes; # I assume these come from somewhere for my $style (qw/ g2d pocus dgp /) { my($in, $out) = ($style . "_ranking", $style . "_rankratio"); # step 1: locate and sort the relevant genes for this ranking style my @set = sort { $a->{$in} <=> $b->{$in} } grep $_->{$in}, @genes; # step 2: get a count my $total = @set; # step 3: update the located genes with a rankratio for my $index (0 .. $#set) { $set[$index]{$out} = ($index + 1) / $total; } }