my $inc = 1 / @data; ## do the invariant once: for ( @data ) { ## $_ aliases each line in turn avoids both the $i-1 and indexing the array $freq{ $1 }[ $-[0] ] += $inc while /(.)/g; ## the regex engine operates directly on the $_ alias. }