in reply to match last element instead of first??
I'm not sure I understand your question. That said, I'd recommend you look into using split for what you appear to be doing. Here's a quick example:
use Data::Dumper; my $restofline = "One fish two fish red fish blue fish"; print Dumper( [ split /\s*fish\s*/, $restofline ] ); __END__ $VAR1 = [ 'One', 'two', 'red', 'blue' ];
If for some reason, you really do have to process the string incrementally, maybe index is a good solution (provided your keyword really is static).
If you really do what to use a regex, I wonder if a non-greedy match is what you're after. That is, "$restofline =~ m/(.*?)fish(.*)/".
|
|---|