my $msgformat = "You have obtained %d %s.\n"; for my $stat (keys %stats) { printf $msgformat, $stats{$stat}, $stat; }