in reply to Comparing 1 array that matches in 2nd array

You could also just use two nested-loops, and, absent any extraordinary provocations to do otherwise, this is probably what I would do.   Something like:   (meant only to sketch the idea)

foreach my $a (@realassert) { foreach my $b (@pcov) { if ($a =~ $b) { push @result, $b; last; // BAIL OUT OF INNERMOST LOOP .. CAN ALSO USE A LABEL } }

There is nothing cryptic or hard-to-understand about logic that has been “unrolled” in this way, and I suppose that this is really my point.   It does the job and it is also obvious what it does, and also how to change what it does.   You don’t have to monkey-around with grep in this-or-that context, in hope of a few sub-milliseconds of completion time, if you’re just going to wind up spending more time getting the damm thing to actually work :-) than you would ever have saved by doing something so “clever.”   Furthermore, if the tests that you need to do in that innermost-loop ever become more complicated ... as they may well do ... then you can easily and confidently change it.   “Golf” games are fun to watch, but not so fun to be a participant.