Your data doesn't entirely make sense, since it's not actually working perl code. I'm guessing that it's a string divided into characters. After that it sounds like you just want to be able to find the highest frequency character, which is essentially just a sort
by descending count.
Therefore the following demonstrates how to count your characters and then sort the results:
use strict;
use warnings;
my $str = '------------------------------------------------------------------MGG-------------------------------------------------------------------------------------';
my @chars = split '', $str;
#Count Characteres
my %count;
$count{$_}++ for @chars;
delete $count{'-'}; # Don't count -
# Sort keys by count descending
my @keys = sort {$count{$b} <=> $count{$a}} keys %count;
for my $key (@keys) {
print "$key $count{$key}\n";
}
Outputs:
G 2
M 1