@words=$text_body =~ /(\S+)/g; #compute $start and $end $newtext=join(" ",@words[$start..$end]); #### # $start and $window $i++ while($i<$start && /(\S+\s+)/g); $i=0; while(/\G(\S+\s+)/g && $i<$window_length) { $newtext .= "$1"; $i++; }