in reply to finding matches in the same array

I guess this is not homework as the source data is presented as two synchronised arrays not a file to read or array of arrays. If it is homework then I recon the OP already did some work to get from a file of data to two arrays.

My output disagrees with the OP's (is actg == acgt ??) and you would be better storing the source data in an array of arrays. I have dumped out the hash of hash I build to collate the data so you can see clearly what is going on. Data::Dumper is fantastic when you are developing any sort of interesting data structure.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; #e.g. my @sequence = ('acgt','actg','cggt','cggt'); my @numbers = ('1234','2345','3244','3455'); my %collated; for (0..$#sequence) { $collated{$sequence[$_]}{total}+=$numbers[$_]; $collated{$sequence[$_]}{number}++; } print Dumper(\%collated); for (sort keys %collated) { print "sequence: $_ = "; print ( $collated{$_}{total} / $collated{$_}{number} ) , "\n"; } __END__ # my output $VAR1 = { 'acgt' => { 'number' => 1, 'total' => 1234 }, 'cggt' => { 'number' => 2, 'total' => 6699 }, 'actg' => { 'number' => 1, 'total' => 2345 } }; sequence: acgt = 1234 sequence: actg = 2345 sequence: cggt = 3349.5

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!