use strict; use warnings; use 5.010; my @arr = ('a', 'b', 'c', 'b', 'b', 'c'); my %hash; for (@arr) { $hash{$_}++; } say %hash; --output:-- c2a1b3
use strict; use warnings; use 5.010; my @arr = ('a', 'b', 'c', 'b', 'b', 'c'); my %hash = ( a => 0, b => 0, c => 0 ); for my $letter (@arr) { my $count = $hash{$letter}; $hash{$letter} = $count + 1; } say %hash; --output:-- c2a1b3