Its normally helpful if you post your code and describe what you are having difficulty with. But I'm at a loose end so try:
#!/usr/bin/perl
use warnings;
use strict;
open (IN, 'first.txt') or die ("crap! $!");
my @first = <IN>;
close IN;
open (IN, 'second.txt') or die ("crap! $!");
my @second = <IN>;
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++;
}