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


in reply to Do nothing? or Do something important in a very obscure way?

/x?/ means match x zero or one times, but prefer 1...
i.e. Match it if you can

/x??/ means match x zero or one times, but prefer 0...
i.e. Match it if you have to

For instance:

% perl -le '"wxy" =~ /(wx?)/; print $1' 1:wx % perl -le '"wxy" =~ /(wx??)/; print $1' 1:w % perl -le '"wxy" =~ /(wx?y)/; print $1' 1:wxy % perl -le '"wxy" =~ /(wx??y)/; print $1' 1:wxy
The notation is a little confusing because the two question marks in a row mean different things. /x?/ is really just syntatic sugar for /x{0,1}/. The second question mark turns on min matching. When you look at it this way, the difference between /x{0,1}/ and /x{0,1}?/ should be more clear.

-Blake