my $count = 0; $array_length = grep m/^.*\n/, @storage; #Storage array contains my file.. Use grep to get the number of sentences for (my $i = 0; $i <= $array_length; $i++) { my $x = 1; if ($storage[$i] eq $storage[$x]) { $count++; } $x++; }