use strict; use warnings; my $result = '2017-08-01 20MICRONS 37744 2016-08-01 20MICRONS 25966 2016-04-20 20MICRONS 30807 2016-04-01 20MICRONS 32780'; my @results = split /\n/, $result; my $total; print "CHECKPOINT\n"; for my $element (@results) { print "$element\n"; my @fields = split /\s+/, $element; $total += $fields[2]; } printf "Average: %.1f\n", ($total / scalar @results); #### 22:47 >perl 1821_SoPW.pl CHECKPOINT 2017-08-01 20MICRONS 37744 2016-08-01 20MICRONS 25966 2016-04-20 20MICRONS 30807 2016-04-01 20MICRONS 32780 Average: 31824.2 22:47 >