For natural language processing (so that, for example, apostrophes are included in words), use instead \b{wb}
"don't" =~ / .+? \b{wb} /x; # matches the whole string ####
use warnings;
use strict;
use feature qw{ say };
if ("don't" =~ / (.+?) (\b{wb}) /x) { # matches the whole string
print "It matches\n";
say $1;
say $2;
}
else {
print "It doesn't match\n";
}
if ("don't" =~ / (.+?) /x) { # It no longer matches the whole string
print "It matches\n";
say $1;
}
else {
print "It doesn't match\n";
}
Output:
It matches
don't
It matches
d