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