sub Esoda_Statistika_button { my @totalExoda = 0; my $sum = 0; my $clearedValue=0; chdir "/home/props/delice/eksoda" or die "didn't make to eksoda folder\n"; #for every txt file in the directory foreach my $file (glob '*.txt') { # open that file open IN, $file; # read through that file line by line while () { #if matches a digit at the specific form if ($_ =~ m/(Exoda.*Total:)(.*\d)/) { #pick that number and store it in $2 $clearedValue =$2; #add all these matched values to @totalExoda push(@totalExoda,$clearedValue); } #end while # sum up numbers of @totalExoda and store it in $sum; foreach (@totalExoda){ $sum+= $clearedValue; print "$sum\n"; } #end if } #end foreach } #end foreach } #end sub