http://www.perlmonks.org?node_id=985252


in reply to regular expression

Your regular expression /.*_?(.*)/ starts with .*, which matches any string of any length. The _?(.*) matches the empty string that remains after your first piece has matched everything. So you captured the empty string.

When you review the manual, pay special attention to the meaning of the quantifiers * and ?.