You don't need to read the MAP file for every line of the input, just read it once
#!/usr/bin/perl
use strict;
open MAPFile,'<',$ARGV[2] or die "$ARGV[2] : $!";
my %hash = (); # Cost Center, Activity
my %hash1 = (); # Account
while ( <MAPFile> ) {
chomp;
my ($CC,$Act,$NEWCC,$NEWAct,$Acct,$NEWAcct) = split(',',$_);
$hash{$CC}{$Act}[0] = $NEWCC;
$hash{$CC}{$Act}[1] = $NEWAct;
$hash1{$Acct} = $NEWAcct;
}
close MAPFile;
open SourceFile, '<', $ARGV[0] or die "$ARGV[0] : $!";
open TargetFile, '>', $ARGV[1] or die "$ARGV[1] : $!";
my $count = 0; my $changed = 0; my $changed1 = 0;
while (<SourceFile>) {
++$count;
my ($Year,$HSP_rates,$Curr,$Scenario,$Version,$Product,
$CostCenter,$Activity,$Entity,$Acct,$BegBal,@mth) = split(',',$_);
my ($NewCC,$NewAct,$NewAcct);
if ( exists $hash{$CostCenter}{$Activity} ){
$NewCC = $hash{$CostCenter}{$Activity}[0];
$NewAct = $hash{$CostCenter}{$Activity}[1];
print "line $count : updated $CostCenter to $NewCC\n";
++$changed;
} else {
$NewCC = $CostCenter;
$NewAct = $Activity;
}
if ( exists $hash1{$Acct} ){
$NewAcct = $hash1{$Acct};
print "line $count : updated $Acct to $NewAcct\n";
++$changed1;
} else {
$NewAcct = $Acct;
}
print TargetFile join ',',
$Year,$HSP_rates,$Curr,$Scenario,$Version,$Product,
$NewCC,$NewAct,$Entity,$NewAcct,$BegBal,@mth;
}
print "$count lines processed
$changed changes to CostCenter,Activity codes
$changed1 changes to Account codes\n";
close SourceFile;
close TargetFile;
Update ; %hash1 added for Acct mappings
poj