#!/usr/bin/perl use warnings; use strict; package MyHash { sub new { my $classname = shift; my $self = {key => shift, value => shift}; return bless($self, $classname); } } my %h = (0 => MyHash->new("a", 10), 1 => MyHash->new("b", 20), 2 => MyHash->new("c", 30), 3 => MyHash->new("d", 40)); my $i; for $i (keys(%h)) { print "The value of the element is \"" . $h{$i}->{value} . "\".\n"; print "And the key is \"". $h{$i}->{key} . "\".\n\n"; }