my %hash; while (){ next unless /Something/; if (//){ if ($hash{$3}){ $hash{$3}{count}++; next; } $hash{$3} = { sig => $1, src => $3, proto => $2, dst => $4, port => $5, }; } }