http://qs321.pair.com?node_id=1143935

nikmit has asked for the wisdom of the Perl Monks concerning the following question:

I know most likely it's in my brain but still, here we go...

I am testing a regular expression and can't quite explain the results to myself with anything but a bug.

my $regex = '(2[0-4]|1?[0-9])?[0-9]'; while (<>) { chomp; if ($_ =~ /^$regex$/) { print "$_ matched\n"; } else { print "$_ did not match\n"; } }
This (as expected) matches digits in the range 1-249.

Changing $regex to ((2[0-4]|1?[0-9])?[0-9])|25[0-5] suddenly matches anything I type as long as it begins with a digit, as if the regex was \d.*

The intended behaviour was to match integers from 1 to 255. What's wrong?