use strict;
-my $sum = 0;
-while (<>) {
- s/\s//g;
- $_ = "($_)";
- 1 while
- s/\((\d+)\)/$1/ ||
- s/(\([^\(\)]*?)(\d+)\+(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
- s/(\([^\(\)]*?)(\d+)\*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e;
- $sum += $_;
-}
-print "sum=$sum\n";
+$_ = '(('.join(')+(', <>).'))';
+s/\s//g;
+1 while
+ s/\((\d+)\)/$1/ ||
+ s/(\([^\(\)]*?)(\d+)\+(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
+ s/(\([^\(\)]*?)(\d+)\*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e;
+print "sum=$_\n";