in reply to regex and embedded perl code

It sounds like the (?{ ... }) blocks are captures. They always referer to the $year, $month and $day variables created by the first call to test. If that's the case, then the solution would be to avoid using lexical (my) variables. The following is an untested (Update: tested) fix:

sub test { my ($date) = @_; print $date,"\n"; our ($year, $month, $day); local (*year, *month, *day); $date =~ m/ (\d+) (?{ $year = $^N }) - (\d+) (?{ $month = $^N }) - (\d+) (?{ $day = $^N }) /x; print "$year-$month-$day\n"; }

I'm assuming this is just a simplifciation of your problem. If not, don't use experiemental features for nothing. Use something like the following instead:

sub test { my ($date) = @_; print $date,"\n"; my ($year, $month, $day) = $date =~ m/(\d+)-(\d+)-(\d+)/; print "$year-$month-$day\n"; }

Of course, you should check if the regexp actually succeeded before using the date components. None of the snippets do this.

Update: Neither yours nor my first snippet work in Perl 5.6.1, but that's because $^N didn't exist before Perl 5.8.0.