use warnings; use strict; my $counter=0; my $tot=0; my $wantedSentence; my $item; my @b=(0,0,0,0,0,0,0,0,0,0); my @a=(15,24,23,110,30,58,3,22,79,6); foreach my $numOfSentences (@a) { $tot=$tot + $numOfSentences; #accumulating totals to @b; $b[$counter]=$tot; $counter++; } print "@b\n"; $counter=0; $wantedSentence = 250; foreach $item (@b) { if($wantedSentence <= $b[$counter]) {$counter++;print "this sentence in chapter $counter";last;} $counter++; }