in reply to Adding hashes to already existing array

I am not completely sure that I understand what you are trying to do. Some of this looks a bit overly complex. Why wouldn't you just use an Array of Array with all 3 parts that you need? Why does there need to be a hash at all?. A simple modification to your @excerpts creation code could be like this:
use warnings; use Data::Dumper; $fc = 'abcdfoofrobnicatebardefforspambazghi'; $re2 = qr/(fo.)(.*?)(ba.)/; my @excerpts; push @excerpts, [$1,$2,$3] while $fc =~ /$re2/g; print Dumper \@excerpts; # Simple iteration over the Array of Array (AoA) # for each row break this down into names that make sense # for your data, whatever they are.. use those names # instead of indicies to process the data. foreach my $rowref (@excerpts) { my($namea,$nameb,$namec) = @$rowref; print "first=$namea second=$nameb third=$namec\n"; } __END__ $VAR1 = [ [ 'foo', 'frobnicate', 'bar' ], [ 'for', 'spam', 'baz' ] ]; first=foo second=frobnicate third=bar first=for second=spam third=baz
Echoing stevieb's comment, it would help if you could manually create an example of the structure that you are trying to build. Or maybe back up a bit and explain how you intend to use the structure and we can suggest some possibilities?

Update: added how to use AoA to the code above.

Replies are listed 'Best First'.
Re^2: Adding hashes to already existing array
by ExReg (Priest) on May 06, 2016 at 20:32 UTC

    The reason I do not use an AoA is because I have several different already existing arrays created similar to @excerpts. Each array has a different number of things that are being extracted, but many of them share similar sub-searches. i.e. I have @excerpts1, @excerpts2, ... and the $re1, $re2, ... will have some (fo.) and (ba.) matching expressions that they would have in common.

    Not sure that makes sense, but different arrarys would have different number of sub-arrays, and I would have trouble keeping them straight if I didn't use hash keys.

    Sorry, It's a Friday, and my brain has already been home for several hours now.