#!/usr/bin/perl # Ivan Novick # Feb, 2008 # each to iterate through a hash use strict; use warnings; # initialize the hash my %countries = ('USA' => 'Washington DC', 'India' => 'New Delhi', 'United Kingdom' => 'London'); # add some more entries $countries{'Germany'} = 'Berlin'; $countries{'Canada'} = 'Ottawa'; # use each to obtain the key and value from the hash while ( my ($country, $capital) = each %countries) { print "${country}'s capital is $capital\n"; }