Since I find your code very difficult to understand, I really do not know what the exact problem is. But, since you are having difficulties, try re-coding, like:
use strict;
use warnings;
my %ext;
opendir H, './';
my @files = grep { -f } readdir H;
closedir H;
for (@files) {
my ($e) = ($_ =~ m/([^.]+)$/);
$ext{$e}++;
}
print "$_ - $ext{$_}\n" for keys %ext;