in reply to Perl/MySQL ?

Kanji is absolutly right you are looking for the SUM() function. You should also learn about all your other aggregate SQL functions.

grep
Unix - where you can throw the manual on the keyboard and get a command