in reply to Special Variables in Regular Expression

I tend to avoid putting ?, +, *, etc on captures. I don't know if the behaviour is even documented, but the behaviour is as follows:

(...)? Returns undef if it matched 0 items. ((?:...)?) Returns an empty but defined string if it matched 0 items.

You can use defined to test in the first case.