"Note that splitting an EXPR that evaluates to the empty string always returns the empty list, regardless of the LIMIT specified."
$rem holds an empty string, so an empty list is assigned to ($middle, $last), setting $middle and $last to undef.
Fix:
use strict;
use warnings;
use List::Util qw( shuffle );
while (<DATA>) {
s/(?<=\w)(\w+)(?=\w)/ join('', shuffle($1=~m{.}sg)) /eg;
print;
}
__DATA__
I couldn't believe that I was actually understanding what I was
reading. The phenomenal power of the human mind, according to
research at Cambridge University, suggests that it doesn't matter
in what order the letters in a word are, as long as the first and
last letters are in the right place. The rest can be a total mess,
and you can still read it without a problem. This is because the
human mind does not read every letter by itself, but the word as
a whole. Amazing, huh? Yeah, and I always thought spelling was
important! Check apostrophe and punctuation: Jame's, They're,
we'll they'd.
By the way, try replacing
shuffle($1=~m{.}sg)
with
sort $1=~m{.}sg
It'll probably be harder to read.