The difference between the two regexes is the placement of your
$ metacharacter, so that should be your red flag. By moving it you are changing your trailing anchor. The first version says:
- Match at least one character that is not a slash
- It should be followed by (non-consuming):
- a slash
- the end of string
The new version says:
- Match at least one character that is not a slash
- It should be followed by (non-consuming):
- a slash
- The last consumed element should be followed by the end of string
In your second regex, the positive look-ahead assertion and the end of string anchor directly conflict. Obligatory documentation refs: perlre, perlretut.