my $acl = {}; $acl->{source} = []; # array of Network address e.g, [10/8,172.16/16] $acl->{dest} = []; # same as above $acl->{original}= 'unknown'; # A string for original ACL e.g, permit ip any 10/8 # After I create a hash I will store the hash reference in an array push @acl_grp, \%acl; # After populating the array of hash refs I want to sort them # I would do something similar to this foreach $acl ( sort compare @acl_grp ){ print $acl->{original},"\n"; } # compare function is coded as # return -1 if $b is a supernet of $a # return 1 if $a is a supernet of $b # return 0 for all other cases, mimicking the behaviour of <=> sub compare($$){some code};