#!/usr/bin/perl use warnings; use strict; open (IN, 'first.txt') or die ("crap! $!"); my @first = ; close IN; open (IN, 'second.txt') or die ("crap! $!"); my @second = ; close IN; my %h; my $i=0; for (@second) { ($h{'A'},$h{'B'},$h{'C'}) = split / /,$_; my @keys = split //,$first[$i]; my $total = 0; for(@keys) { $total+= int($h{$_}) unless /\n/; } $total/=scalar(@keys) if($total); print "$i: $total \n"; $i++; }