The problem is that, even though you're using non-greedy matching, Perl still works from left to right, return the left-most longest match that satisfies your regex. If you'd done s/:.*?// you would have been left with "fruitred:apple", but since you have s/:.*?$//, Perl needs to match "end of string", and the .*? then matches all the way from after "fruit:" to the end of the string. Using non-greedy matching and the $ anchor won't get you the result you expected; you'll need to use a more specific regex like s/:[^:]*$//.
Also, the /o modifier is utterly useless here.
In reply to Re: Why doesn't this s/regex// work?
by japhy
in thread Why doesn't this s/regex// work?
by nneul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |