#!/usr/bin/env perl use 5.010; use strict; use warnings; # newbie but clean version sub max_value_of_hash { my $h = shift; my $max = 0; for my $v (values %$h){ if ($v > $max){ $max = $v; # keep setting $max to larger value } } return $max; } # more perlish and elegant version sub max_value_of_hash2 { my $h = shift; my $max = 0; $_ > $max ? $max = $_ : undef for values %$h; return $max; } # let a module do it sub max_value_of_hash3 { use List::Util qw(max); return max values %{$_[0]}; } my %hash = ( a => 1, b => 2, c => 5, d => 3 ); say max_value_of_hash( \%hash); say max_value_of_hash2(\%hash); say max_value_of_hash3(\%hash);