#!/usr/bin/perl # My old code use strict; use warnings; my %hashName = ( "term1" => 83, "term2" => 20, "term3" => 193 ); my $i = 0; my $max = 0; foreach (sort sortHash (keys (%hashName))) { if ($i == 0) { $max = $hashName{$_}; last } } # end-foreach sub sortHash { $hashName{$b} <=> $hashName{$a}; }