For each index (for my $i (0..length($seq)-1)), it gets the letter at that index in each label (map substr($_, $i, 1), @lbls).
To calculate the consensus, the number of instances of each letter is counted ($counts{$_}++ for @_;). Then the letters (keys(%counts)) are sorted by descending number of instances (sort { $counts{$b} <=> $counts{$a} }), and one of those with the highest count is returned (( )[0]).