while (){ my ($source, $sport, $to, $dport, $proto, $packs, $bytes) = split; if ( $total{"$source$dport"}{'from'} ) { # if source exist $connects{"$source$dport"}++; if ($total{"$source$dport"}{'to'}) { # and destination exist - summarizing $total{"$source$dport"}{'bytes'}+=$bytes; } else { print "oops"; } # this seem we can't get here, but I don't get why... } else { $total{"$source$dport"} = { "from" => $source, "to" => "$to:$dport", "bytes" => $bytes } } $total+=$bytes; }