If you have to evaluate the average for all sequences, you can build the following hash:
my %occurrences;
push @{$occurrences{$sequence[$_]}}, $numbers[$_]
foreach (0 .. $#sequence);
At this point, each entry in the hash has a "sequence" for key and a reference to an array containing the "numbers" for that sequence as value - computing the average should be pretty easy, e.g.:
my $sum;
$sum += $_ foreach (@{$occurrences{'atcg'}});
my $average = $sum / scalar(@{$occurrences{'atcg'}});
I leave the union of the two snippets as an exercise, just in case it's an homework :)
Update: fixed a typo in first snipped, thanks to Postular Postulant.
Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")
Don't fool yourself.