#!/usr/bin/perl -w use strict; use warnings; my $sum; my $count; open my $input, '<', 'meres.txt' or die "ERROR: $!\n"; while(my $line = <$input>) { # read line to $line chomp $line; # remove eol if ($line =~ /(-?\d+)/) { # match to numbers and optional leading minus, the match will be in $1 #print($1."\n"); $sum += $1; # summing up $count++; # count items } } close $input; print 'Average: ', $sum/$count, "\n";