for my $word (keys %counter){ print "You typed $word $counter{$word} time" .($counter{$word}>1 ? 's' : ''). ".\n"; # or printf "You typed %s %d time%s.\n", $word, $counter{$word}, ($counter{$word}>1?'s':''); }