my $iVal = $ranges[$range]{last}++; becomes my $iVal = ++$ranges[$range]{last};