Because that's not how the return value of matches is defined.
In scalar context, a succesful match returns the number of
times it matched. Without the /g, this will always be 1. With /g, this might be more, but
that wouldn't help in your case. An unsuccesful match in
scalar context returns the empty string, regardless of any
flags.
That's the way how it works, and if you want to have different
values depending what matched, you need to do a little more
work.
Abigail | [reply] [d/l] [select] |