#! /opt/local/bin/perl -w # I recommend the strict pragma if you are new to perl use strict; # you could get the data you provided into an array in any # number of ways. my @data = ("1234-5678 12 .345678", "1234-5678 90 .123456"); my $sum; foreach (@data) { # puts each piece of information into its own variable # in case you need to use them for something. # you could push them into arrays to keep track of them my ($user_id, $proc_id, $time) = split(); # adds the time from the current line to the running # total of time values $sum += $time; } # divides the total times by the total number of times # (the index of the last element in the array + 1) my $average = $sum/($#data + 1); print $average;