in reply to Re: Re: Regex question
in thread Regex question

To reiterate NetWallah's point, you won't get into the loop if the regex doesn't match, meaning that if you do get into the loop, there will be something in $1, so any code to set a default value won't be called. If you have to run what is presently in the if block regardless of rather or not the match was successful, then it probably shouldn't be an if block.

You may wish to use something along the lines of thelenm's second snippet instead, something like this:

$match = ($string =~ /foobar(...)/) ? $1 : "chiapet"; push (@array, $match); bunch of other stuff...

note the lack of the if block...

Just Another Perl Alchemist