I am the author of the above comment. Something like this seems to work:
$result =~ /\A/g or die; # make extra sure we are at start of string
@r = ($result =~ m/\G(foo)/gc);
if ($result =~ /\G(.+)/sg) {
warn "leftover junk at the end of result: $1";
}
The key is the /c flag on the repeated match so that when it fails, it leaves the match position in place so the trailing junk, if any, can be reported.
If there is leading junk, then the regexp won't match any times, and the whole string will be reported as 'leftover'. That is a good enough error message for my purposes.