Your code as posted does not compile:
$ perl -cw 11135816.pl No such class list at 11135816.pl line 6, near "my list" syntax error at 11135816.pl line 6, near "my list =" syntax error at 11135816.pl line 9, near "$1 print" Global symbol "$the_rest" requires explicit package name at 11135816.p +l line 10. Bareword "list" not allowed while "strict subs" in use at 11135816.pl +line 6. 11135816.pl had compilation errors.
Cleaning it up and fixing the regex by anchoring to the end and allowing spaces in the first group we have:
use strict; use warnings; my $list = "This is my list"; $list =~ /(.+)\s(\w+)$/; my $last = $2; my $the_rest = $1; print $the_rest . "\n"; # "This is my" print $last . "\n"; # "list";
🦛
In reply to Re: Match last word in a sentence
by hippo
in thread Match last word in a sentence
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |