use strict; my $VAR1 = { 'wizard' => { 'spell' => 4, 'ppd' => 10, 'breath weapon' => 9, 'pp' => 7, 'rsw' => 5 }, 'warrior' => { 'spell' => 6, 'ppd' => 3, 'breath weapon' => 4, 'pp' => 4, 'rsw' => 5 }, 'rogue' => { 'spell' => 7, 'ppd' => 9, 'breath weapon' => 12, 'pp' => 8, 'rsw' => 6 } }; my $stat = 'spell'; my $smallest; foreach my $class (keys $VAR1) { my $val = $VAR1->{$class}->{$stat}; if (!$smallest) { $smallest->{'class'} = $class; $smallest->{'val'} = $VAR1->{$class}->{$stat}; } else { if ($smallest->{'val'} > $VAR1->{$class}->{$stat}) { $smallest->{'class'} = $class; $smallest->{'val'} = $VAR1->{$class}->{$stat}; } } } print "Smallest value for $stat is in class $smallest->{'class'}, with value $smallest->{'val'}";