my $key = join '|', "$month.year", $fmt_proto, $fmt_dest_ip, $fmt_dest_port, $fmt_src_ip, $fmt_src_port; $mon_log{$key} += $fmt_drp_packets; #### create table stuff ( proto char(4), src_ip char(15), etc.... drp_packets int, index(proto), index(src_ip), etc.... ) load data local infile '/blah/blah.dat' into table stuff select sum(packets) where src_ip = 1.2.3.4 and ..... #### my $current_rec = ''; my $current_count = 0; my($proto, $dest_ip, $src_ip, $dest_port, $src_port, $drp_packets, $country, $rec); while(){ ($proto, $dest_ip, $src_ip, $dest_port, $src_port, $drp_packets, $country) = split' '; $rec = join "\t", $proto, $dest_ip, $src_ip, $dest_port, $src_port; if ( $rec eq $current_rec ) { $current_count += $drp_packets; } else { print OUTFILE $current_rec, "\t", $current_count; $current_rec = $rec; $current_count = $drp_packets; } } # now print any hanging rec print OUTFILE $current_rec, "\t", $current_count if $rec eq $current_rec;