Hi Chas, Look at the following code. It does not change the $cdr[13] value after processing as is desired.
#!/usr/bin/perl use strict; use warnings; my $file_path = '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/ratetest'; my $write_path = '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/rateop' ; my %prefix_to_rate = ( '+1' =>0.20, '+65' =>0.30, '+673'=>0.45, '+86' =>0.45, '+852'=>0.45, '+853'=>0.45, '+66' =>0.45, '+212'=>1.50, '+234'=>1.50, '+47' =>1.50, '+48' =>1.50, '+7' =>1.50, '+27' =>1.50, '+46' =>1.50, '+380'=>1.50, '+93' =>1.50, '+62' =>0.22 ); my %times ; my %hash ; my ($shortest, $longest) = (sort { $a <=> $b } map {length} keys %prefix_to_rate)[0, -1]; my $continue = 1; $SIG{INT} = $SIG{TERM} = sub { $continue = 0 }; while ($continue) { opendir my $dh, $file_path or die $!; while (my $file = readdir $dh) { my $fname = "$file_path/$file" ; next unless -f $fname; unless (exists $times{$file}){ my $line; open (my $IN_FILE,"<","$file_path/$file") or die $!." file not found" ; while ($line=readline($IN_FILE)) { my @cdr=split (/,/, $line) ; my $rate; if($cdr[22] eq "Budget-IDD" ) { for my $len (reverse $shortest .. $longest) { my $key = substr $cdr[3],0,$len; last if $rate = $prefix_to_rate{$key}; if (defined $rate) { $cdr[13] = ($cdr[6]/20)*$rate ; } } } $line = join(",",@cdr); [EMAIL PROTECTED],3,6,7]}=$line; } close $IN_FILE ; open (my $OUT_FILE,">>","$write_path/$file.out") or die $!; while (my($key, $value) = each %hash) { print $OUT_FILE $value; } close $OUT_FILE ; } } closedir $dh ; } Following is the sample input data:- 2007/08/18 23:09:51,999,+60139169925,+6281917457237,,1,17,2007/08/18 23:09:34,357953001453930,502191402472982,30421,3,4117773,5.5 ,2,1,1,1,,0,8,+60139169925,Budget-IDD,,9KTTB,Alcatel,5419496593,1 2007/08/18 23:10:03,999,+60199514513,+6681805297189,,1,5,2007/08/18 23:09:58,353377004203470,502191200047108,33761,3,8893845,5.5 ,2,1,1,1,,0,8,+60199514513,Budget-IDD,,9KTTB,Alcatel,5419496808,1 2007/08/18 23:10:09,999,+60139484541,+62081933039638,,1,5,2007/08/18 23:10:04,359772006475961,502191402477236,36433,3,4357348,5.5 ,2,1,1,1,,0,8,+60139484541,Budget-IDD,,9KTTB,Alcatel,5419496906,1 2007/08/18 23:10:19,999,+60139433881,+4781917453095,,1,559,2007/08/18 23:01:00,354388004016271,502191501305123,33802,3,10638343,55,2,1,1,1,,0,8,+60139433881,Budget-IDD,,9KTTB,Alcatel,5419497064,1 2007/08/18 23:10:27,999,+60148482721,+6285937021269,,1,86,2007/08/18 23:09:01,354813018414143,502191201919440,36643,3,4891400,11,2,1,1,1,,0,8,+60148482721,Budget-IDD,,9KTTB,Alcatel,5419497197,1 Thanks, Mihir