#!perl -w use strict; my @lines; while (<>) { push @lines, $_; shift @lines if @lines > 10; } chomp(@lines); my @cols; my $total = 0; for (@lines) { @cols = split /:/; $total += $cols[3]; } my $average = $total / (@lines || 1); # if no lines, avoid division by zero print "Average of column 3 for the last ", scalar(@lines), " days: $average\n";