sample of company data: COMPANY-A, COMPANY-B, COMPANY-C, etc. #### while (<$file>) { my @f = split '\s+', $_; # if ($f[0] =~ (/COMPANY-A/)) { # this is just for 1 company and not efficient normally i remark this out if ( $f[0] =~ (/-C$/)) { # this process carryover records my @ymd1 = split ',',$f[4] //= $prev_mth_end; # fill empty dates with previous month end my @ymd2 = split ',',$f[5] //= $prev_mth_end; my $diff = Delta_Days(@ymd1, @ymd2) +1; # total days my $prev = $prev_days{$f[2]} //= 0; my $amt = ($diff + $prev > 3) ? $diff + $prev - 3 : 0; # days to be charged my $cost = ($amt) * 100; my $free = $diff - $amt; my $stg_chg = "N/A"; #static field my $sw_chg = "N/A"; #static filed my $waive = " "; my $cartot = ($cost + $stg_chg + $sw_chg); my $comment = "Carry over from last month"; my $pfmt = "%-12s %-5s %-8s %-5s %-15s %-15s %-6s %-6s %-8s %-12s %-12s %-12s %-8s %-12s %-40s\n"; printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]), $diff, $free, $waive, fmt_curr($cost), $stg_chg, $sw_chg, $f[6], fmt_curr($cartot), $comment; } #process non-carryover records else { my @ymd1 = split ',',$f[4] //= $prev_mth_end; # fill empty dates with previous month end my @ymd2 = split ',',$f[5] //= $prev_mth_end; my $diff = Delta_Days(@ymd1, @ymd2); my $prev = $prev_days{$f[2]} //= 0; my $amt = ($diff + $prev > 3) ? $diff + $prev - 3 : 0; my $cost = ($amt * 100); my $free = $diff - $amt; my $stg_chg = "N/A"; #static field my $sw_chg = "N/A"; #static field my $waive = ""; my $cartot = ($cost + $stg_chg + $sw_chg); my $comment = " "; my $pfmt = "%-12s %-5s %-8s %-5s %-15s %-15s %-6s %-6s %-8s %-12s %-12s %-12s %-8s %-12s %-22s\n"; printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]), $diff, $free, $waive, fmt_curr($cost), $stg_chg, $sw_chg, $f[6], fmt_curr($cartot), $comment; } # } }