in reply to Why doesn't this s/regex// work?

AGH!

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.


Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart