in reply to get last matches of the given string

There are a number of ways to do what you want.
- anchor to the end to get the last word match
- use list slice to get last or even second to last word
my ($last) = $in =~ m/(\w+)$/i; print "last=$last\n"; my ($second_to_last) = ($in =~ m/(\w+)/gi)[-2]; #[-1] would have been +last print "second to last=$second_to_last\n"; __END__ Prints: last=senthil second to last=foo
Note that Perl shortcut of \w also includes _0-9 Often this doesn't matter and I just use the \w instead of making a special set.