$s = 'This is the word'; $s =~ s[(^\S+)(\s.*\s)(\S+$)][$3$2$1]; print $s; word is the This