while (<>) { s/\r?\n$//; my @c = split /$sep/o; my $sub_total = 0; $sub_total += $c[14]; my $key = join $sep, @c[ @col ]; if (not defined $lines{ $key }) { $lines{ $key } ||= []; }; push @{ $lines{$key}}, $_ push @{ $totals{$key}}, $sub_total }