in reply to Re: Assigning a varable inside of (?{})
in thread Assigning a varable inside of (?{})

One solution is to use globals for this situation.

Yes, global (lexical or package) variables will do the trick, but localized package variables would be better:

sub get_time { my ($string) = @_; local our ($sunrise, $sunset); $string =~ / sunrise: \s+ (\d+:\d+) (?{ $sunrise = $^N }) \s+ sunset: \s+ (\d+:\d+) (?{ $sunset = $^N }) /x; return ( \$sunrise, \$sunset ); }
...or rethink your regexp strategy.

I think this would be the proper course of action here. Using (?{...}) is overkill, and using $^N imposes a requirement for Perl v5.8.0+ needlessly. The OP could use the following simple expression:

sub get_time { my ($string) = @_; my ($sunrise, $sunset) = $string =~ / sunrise: \s+ (\d+:\d+) \s+ sunset: \s+ (\d+:\d+) /x; return (\$sunrise, \$sunset); }

By the way, why return references to the values? return ($sunrise, $sunset); would make more sense.