use strict; use warnings; my $test = 'abc'; my @matches; $test =~ /(a(bc?)?)(??{push @matches, $^N})(?!)/; print "@matches\n";