#!/usr/bin/perl # print_sum - read from stdin and print the sum. $total = 0.0; while (<>) { if (m/^\s*([\d.]+)/) { $maybe_number = $1; $maybe_number =~ s/\.*$//; # chop trailing ".". if ($maybe_number =~ m/\d/) { $total += $maybe_number; } } } print "$total\n";