use List::Util qw( reduce ); my $highest_rated = reduce { $a->{Rating} >= $b->{Rating} ? $a : $b } grep $_->{Season} == $seasonnum, values %$hdata; my $banner_path = $highest_rated->{BannerPath}; #### my $highest_rated; for (values(%$hdata)) { next if $_->{Season} != $seasonnum; $highest_rated //= $_; if ($_->{Rating} > $highest_rated->{Rating}) { $highest_rated = $_; } } my $banner_path = $highest_rated->{BannerPath};