$ perl -F'\|' -nale '$x[$F[0]-1]+=$F[1]}{print"the total is: ($_)"for@x' input.txt the total is: (150) the total is: (75) the total is: (55)