{ # initialize counters my %counter = map { $_ => 0 } qw( Ok Warning Error Fatal ); sub increase_counter { my $id = shift; die "(E) Specified counter '$id' does not exist!\n" if not exists $counter{$id}; $counter{$id}++; } sub show_counter { for my $k ( sort keys %counter ) { printf "%10s : %s\n", $k, $counter{$k}; } } } # increase specified counter increase_counter('Ok'); # show values of all counters show_counter();