in reply to Regex Semantics
The regexp ^a*$ says that there may be zero or more a characters followed by an optional newline and then the end of the string. When $foo is '1' then the end of the string is tested before matching the '1'. Your pattern succeeded when you omitted $ because you didn't require that the you'd gotten to the end of the string. '1' =~ /^a*/ succeeds with no characters matched like /^/ while 'a' =~ /^a*$/ succeeds with all three parts matched: /^a*$/.
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
|
|---|