in reply to Capturing everything after an optional character in a regex?

Use looking behind -
$string =~ /((?<=X)\S+)/;
Note that this only sets $1 if X is present.

Can you please phrase your question more clearly, ie. what's the behaviour you are expecting? What do you want to capture when X is not present?