foreach my $file (@ARGV) { open(FILE, "$file"); my $sum = 0; while () { chomp(); $sum+=$_; print "$file $_\n"; $total+=$sum; } print "Total value for the $file : $sum\n"; close( FILE ); }