in reply to regex and embedded perl code

Another solution, if you want $year, $month, $day in lexical context and assign the data with $^N use a closure.
#!/usr/bin/perl use strict; my $foo_year = "2004-11-12 12:40:42"; test($foo_year); test($foo_year); test($foo_year); { my ( $year, $month, $day ); sub test { my ($date) = @_; print $date, "\n"; $date =~ m/ (\d+) (?{ $year = $^N }) - (\d+) (?{ $month = $^N }) - (\d+) (?{ $day = $^N }) /x; print "$year-$month-$day\n"; } } __OUTPUT__ 2004-11-12 12:40:42 2004-11-12 2004-11-12 12:40:42 2004-11-12 2004-11-12 12:40:42 2004-11-12
Boris