in reply to appending and array into last element of an array?

Each pass through saves the position of each match to a string into an array (arrayB). This array of matches to the first string becomes the first element of arrayA.

You need two values here, either position + length or start-positon and end-position of each match. Perl provides the variables @- and @+ for the latter. An example is in perlretut.

You could store these values in a single string, e.g. "16-25", or store them in an array. To push that array into arrayB, the array's representation has to be a scalar, because there can only be one element in each slot of an array. So, you need an anonymous array which can be accessed via a reference (see e.g. perlreftut).

my @arrayC; while(defined($textblock) = <>) { my @arrayA = (); foreach my $string (@strings) { my @arrayB = (); while($textblock =~ /$string/) { push @arrayB, [ $-[0], $+[0] ]; } push @arrayA, \@arrayB; } push @arrayC, \@arrayA; }

Note that we take references to the lexically scoped arrays @arrayA and @arrayB (with the "\" operator, see perlop), which are re-initialized at each pass through their loop block.

Ideally, I would then format each text block to highlight each string-match in a particular color, based on the position of hits stored in each ArrayB, corresponding to the particular string matched stored in each ArrayA, corresponding to the text block the hits are found in (the position in ArrayC.

So you need to save your textblocks somewhere to do the formatting, if you don't want to read the file twice. You could store it together with the correspondig matches you've found in @arrayC (instead of storing the matches only):

push @arrayC, [ $textblock, \@arrayA ];

-shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}