I wrote a code that gives as an output phone models in a country with the number of users using the model, I have attached the output here. As you may notice, there are duplicates of phone models and what I would like to do is add the values of these duplicates in order to have a unique model

Your code could likely be optimised to produce the end result more efficiently, but for simplicity I propose adding another level of data crunching, a hash where its keys are the phone model and its values are a running total of users.

Declare the hash at the top with your other variable declarations:

Code

my %output;

Instead of printing, construct the proposed hash. If the model already exists in the hash, it will add the current count to the existing count:

Code

print "$count\t$model";$output{$model} += $count;

Output the hash at the end. Usually you would have to print a newline character on the end, but since you didn't chomp it off the model earlier, its not necessary:

Code

print "$output{$_}\t$_" for ( keys %output );

If you want to order the data highest to lowest number of users you could use the below instead: