How I can sort the value of hash and count them for related key.

For example : 
push @{$name\_hash{$st\_name}},$end\_name;

```
 $VAR1 = 'firstname')';
    $VAR2 = [
      'lastname1',
      'lastname1',
      'lastname1',
      'lastname2',
      'lastname2',
      'lastname2',
      'lastname3',
      'lastname3',
       ] 

```

I need table like

```
    `firstname : lastname1 : 3`  

    `firstname : lastname2 : 3`

    `firstname : lastname3 : 2`

```

I tried using some counter but its failing either at start where I am having only value multiple time or at the end of the last value (in this case lastname3). 

```
foreach $n (sort keys %name_hash) {
    $ecounter =0; $temp2 = "NA"; $tcount =0; $p =0;
    foreach $lastn (sort values @{$name_hash{$n}}) {
        $ecounter ++ if ($lastn eq $temp2);
        $tcount++;
        if (($tcount) > ($ecounter+1) ){
        print " $n : $temp2 : $ecounter+1\n";
        $ecounter=0; $tcount=1;
        $p =1 ;
        }
        $temp2 = $lastn ;

       }

    print "$n : $temp2 : $ecounter+1\n" if (!$p);

    }

```