I think you have most of this solved. You even already have the numbers in a variable, ready to use. In the following line,
if (/(\d{1})(\,)(\d{3})/) { the part of the string that is represented by each set of parentheses within the match is assigned a numeric variable ($1, $2, etc.). So the first input line would look like this: if (/(\d{1})(\,)(\d{3})/) { # $1 == 1, $2 eq ',', $3 == 200 So, assuming you are adding the numbers after the comma (I'm not sure of the file format), you could add this line just after 'print OUTPUT': $total += $3; #add the string caught by the third set of () Or, if the comma is just the zero separator for a number in thousands, you would add this: $_ =~ s/,//g; #get rid of the comma $total += $_; #add the result to $total at the end $total should have the total sum. P.S. I took the CGI group out of my reply. People get a little annoyed when they get multiple messages because you cross-posted. -----Original Message----- From: Bruce Ambraal To: [EMAIL PROTECTED] Cc: < Sent: 3/16/02 9:17 AM Subject: Adding the input file digits together (Come on guys) Hi I am want to add digits in In_digits together. Print total to screen. Could someone help? Thanx Bruce In_digits: 1,200 2,400 #!/usr/bin/perl -w open(INPUT, "In_digits") || die; open(OUTPUT, ">Out_digits") || die; while (<INPUT>) { if (/(\d{1})(\,)(\d{3})/) { print OUTPUT; } else { print "warning: line of unexpected format ($_)\n"; } print } close(INPUT); close(OUTPUT); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -------------------------------------------------------------------------------- This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]