#!/usr/bin/env perl use strict; use warnings; my ($sum, $cnt) = 0; /^\d$/ and ++$cnt and $sum += $_ while (<>); print $sum/$cnt . "\n";