my $str1 = q/It is a guide to action which ensures that the military always obey the commands of the party./; my $str2 = q/It is a guide to action that ensures that the military will forever heed Party commands is a guide./; for my $str ( $str1, $str2 ) { print "=== input is [$str] ===\n"; my @words = split / /, $str; while ( @words >= 3 ) { print join( " ", @words[0..2] ), "\n"; shift @words; } print "\n"; }