# I've snipped out what I consider to be the important bits... # Warning: This is untested code! # First, store the sn count inside the DEVICE, since we have one DEVICE per $sn struct ( DEVICE => { datetime => '$', devicetype => '$', zip => '$', version => '$', sn_count => '$'}); # Get the $sn and other fields here # If this is the first time we see $sn, populate the DEVICE if (!exists $SNs{$sn}) { $SNs{$sn} = new DEVICE; $SNs{$sn}->datetime('$datetime'); # etc. } # update the sn_count for this $sn. $SNs{$sn}->sn_count($SNs{$sn}->sn_count + 1); foreach my $key (keys %SNs) { print "$key\n"; }