my %list; my ($customer, $total); # use $customer instead of $cust format STDOUT_TOP = +-----------------------------------------------------------------+ | Monthly Recap | |----------------------------+----------+-----------+-------------+ |Account | Prior | Current | Difference | |----------------------------+----------+-----------+-------------+ . format STDOUT = |@<<<<<<<<<<<<<<<<<<<<<<<<<<<|@#####.## | @#####.## | @#####.## | $customer, $list{$customer}->{prior}, $list{$customer}->new, $total |----------------------------+----------+-----------+-------------+ . &readfile('sfoct01.txt', 'prior'); # &readfile('sfnov01.txt', 'new'); &printdata; sub readfile{ my ($file, $money) = @_; my ($line, $amount); die unless open FH, $file; while ($line = ){ chomp($line); my ($cust, $amount) = split('",',($line)); # localise this $cust $cust =~ s/"//g; if (exists $list{$cust}){ $list{$cust}->{$money} += $amount; } else{ $list{$cust}->{$money} = $amount; } $list{$cust}->{new} = 10; } close FH; } sub printdata{ foreach my $cust (sort keys %list){ # localised $cust $customer = $cust; # assign to $customer $total = $list{$cust}->{new} - $list{$cust}->{prior}; write; } }