open (IMEI, 'IMEI.txt'); open (TAC, 'tac.txt'); %mapToModel =(); %keyCount = (); while (){ $key = substr $_,0,8; $model = substr $_,9; $keyCount{$key} = 0; $mapToModel{$key} = $model; } close (TAC); while (){ $subs = substr $_, 0, 8; if(exists $keyCount{$subs}){ $keyCount{$subs} = $keyCount{$subs}+1; } } close (IMEI); foreach $key (keys %keyCount){ if (exists $mapToModel{$key}){ $model = $mapToModel{$key}; $count = $keyCount{$key}; if( $count !=0){ print "$count\t$model"; } } }