#!/usr/bin/perl use warnings; use strict; my @country = ( "Australia", "south","Austria","America","India","Zimbabwe" ); # build a table - a hash of arrays (HoA) my %table; foreach my $country (@country) { my $init = uc substr($country,0,1); push @{$table{$init}}, $country; } # output the table for my $letter (sort keys %table){ print qq{$letter = }; for my $country (sort @{$table{$letter}}){ print qq{$country }; } print qq{\n}; } #### A = America Australia Austria I = India S = south Z = Zimbabwe