In Perl (and unlike Java), the m//
-match operator is not anchored by default.
As such all of the input it trivially matched by both /hello?/
and /hello*/
. That is, these will match any string that contains "hell" (as both quantifiers make the "o" optional) anywhere.
Compare with /^hello?$/
and /^hello*$/
, respectively. Since these employ anchors the former will not match "helloo" (as at most one "o" is allowed) while the latter will.
Under Regexp Quote-like Operators:
m/PATTERN/
searches [anywhere in] a string for a pattern match, and in scalar context returns true if it succeeds, false if it fails.