in reply to Printing Output in different way

hash keys come in any order at all (not like an array where there is a fixed order). To print in alphabetic order you need to sort the keys.

#!/usr/bin/perl use strict; use warnings; my %hash2=( c => "cat", a => "apple", b => "boy", ); my @keys= sort keys %hash2; foreach my $s (@keys) { print "$hash2{$s} "; } __END__ prints: apple boy cat