ok How many times that ID2(string/number) is repeated in the file if the string is found ,then we have to add the amount to old amont ( i will take care of this addition) This is what i hva etried .but in vain

You have several errors. The largest by far is your nested while's. You should only read the file once.

Always begin a script with

Code

use strict; use warnings;

They do require you to declare your variables. You are already doing this.

'identity' contains a single value. It is a scalar and should be declared with a $ instead of @.

qw is for arrays. Just use the quotes. (Even these are not needed for a number)

Use a lexical file handle. (Start with a $. Declare with 'my')

Use the three argument form of open. (refer perldoc -f open)

Your data format is called 'csv' (comma separated values). Your regex is not even close to parsing correctly. In general I would recommend using a csv module. In this case, it would be easier to use the perl function split (refer perldoc -f split) to divide each line into fields.

Do the addition inside your main loop. (Declare the sum outside the loop.)

If you still need help, show us your revised code and ask specific questions. Good Luck, Bill

It probably works, but I certainly would not do it that way. To me, this is a misuse of the map function (although you are obviously free to use it the way you want). And, especially, this is emphatically not what I would suggest to the OP, who is obviously a beginner.

An easier approach for a beginner might be something like this (type directly on this post and untested):