in reply to finding matches in the same array

use two hashes, one for totals an other for counters, them use two loops, one to populate these hashes and other to calculate the averages as total/counter:
my @sequence = ('actg','actg','cggt','cggt'); my @numbers = ('1234','2345','3244','3455'); my (%total, %count, $i); for ($i=0; $i<@sequence; $i++) { $total{$sequence[$i]}+=$numbers[$i]; $count{$sequence[$i]}++; } for (sort keys %total) { my $avg=$total{$_}/$count{$_}; print "$_ avg: $avg\n"; }