#!/usr/bin/perl use strict; use warnings; package my_package; sub new { my $class = shift; my $obj = { HASH => { "key1" => 35, "key2" => 28, "key3" => 74, }, }; return bless $obj, $class; } sub outer_subroutine { my $obj = shift; sub sort_by_value { $obj->{"HASH"}{$b} <=> $obj->{"HASH"}{$a}; } foreach my $key ( sort sort_by_value(keys $obj->{"HASH"} ) ) { print $key, "\n"; } } package main; my $object = my_package->new; $object->outer_subroutine;