A hash value can be updated, and sorted keys make the printed result predictable.

Hash Update Count

hash_update_count.pl
use strict;
use warnings;

my %counts = (
    red  => 2,
    blue => 1,
);
my $color = ;
$counts{$color} += 1;
my @keys = sort keys %counts;
my $key_list = join(",", @keys);
my $value = $counts{$color};

print "color=$color\n";
print "value=$value\n";
print "keys=$key_list\n";
use strict;
use warnings;

my %counts = (
    red  => 2,
    blue => 1,
);
my $color = ;
$counts{$color} += 1;
my @keys = sort keys %counts;
my $key_list = join(",", @keys);
my $value = $counts{$color};

print "color=$color\n";
print "value=$value\n";
print "keys=$key_list\n";
use strict;
use warnings;

my %counts = (
    red  => 2,
    blue => 1,
);
my $color = ;
$counts{$color} += 1;
my @keys = sort keys %counts;
my $key_list = join(",", @keys);
my $value = $counts{$color};

print "color=$color\n";
print "value=$value\n";
print "keys=$key_list\n";
hash update Assigning through a hash key changes the stored value for that key.