A sample of your data and verbatim reports on your messages (are you sure they're 'error' messages, rather than warnings?) would be a great help in finding a way to help you.

But, that said, this is a llama-level primer-version of an approach to your titled issue:

#!/usr/bin/perl use 5.014; my @matches; my @arr = qw/a1 ab2 aab3 ac4 dc5 bc6 da7 cb8 dbca9 aa0/; for $_( @arr ) { if ($_ =~ m/a/g) { say "\t regex matches $_"; push @matches, $_; } } for my $match( @matches) { say $match; }

Note that this pushes each capture to the array, rather than replacing the array repeatedly, thus preserving only the last. That's something which you might have spotted in the course of writing your question, had you provided the data.

For the reasoning behind this, see Re: a bit of monastery zen.

Update: One and all may consider this another illustration of the danger another Monk noted recently; the danger of keeping a tab open too long (long enough to answer a false alarm, in this case).


In reply to Re: Help with placing the matches of a regex into an Array by ww
in thread Help with placing the matches of a regex into an Array by kereekerra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.