adding a list of numbers 3 by 3

i have a list of numbers like this;

124
235
764
782
765
451
983
909
...

and i want to make a sum with the first 3 of them then the next 3 and so on.

124+235+764=1123
782+765+451=1998
...

some ideas?

 awk 'NR%3 == 0{sum+=$0;print sum;sum=0}NR%3 >0{sum+=$0}' filename

-Devaraj Takhellambam

the algorithm is quite simply:

1) set a counter and a total
2) open the file
3) for each line
4) set counter=counter+1
5) set total=total+line
6) check if counter == 3
6a) if counter is 3, print the total and set count=0

now, you can get going....

Something like this:

perl -ne '/(\d+)/;$t+=$1;if($.%3==0){print $t,"\n";$t=0;}'

Thanks everybody; i got it.