Basically, what is happening is that when greedy constructs fight, the left one wins. In your pattern m/(.*)fish(.*)/) There are two (.*) constructs that try to get as many characters as they can without failing the match. The first one gobbles up until the last fish (because if it ate the fish, your "fish" couldn't match), then the "fish" matches, and only then is the last (.*) let to grab as much as it can.
As stated above, you either want the non-greedy version in front (if you want to split the string only on the first "fish") or the split function (which is appropriate if you don't mind splitting on each fish in the line).
Also as stated above, read perlre early and often. I've read it in the last week and I was still thrown for a loop by Corion's post above, my interpretation of the pattern was very wrong.
In reply to Re: match last element instead of first??
by amarquis
in thread match last element instead of first??
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |