$file = $ARGV[0]; #punctuation characters $punc = "[\.!\?]+[\"']? *"; open(F, $file) or die("Can't open file.\n"); #split each line into fragments using $punc while ($line = ) { chomp($line); if (length($line) > 1) { push(@fragments, mysplit($line)); } } close(F); #add all fragments together until an instance of punctuation for ($i = 1; $i < $#fragments; $i++) { if ($fragments[$i-1] !~ /$punc/) { $fragments[$i-1] .= $fragments[$i]; splice(@fragments, $i, 1); $i--; } } #print out each sentence for ($i = 0; $i < $#fragments; $i++) { print("$fragments[$i]\n\n"); } #splits the line repeatedly into fragments sub mysplit { my(@frags, $line); $line = shift(); while ($line =~ /$punc/) { push(@frags,$`); push(@frags,$&); $line = $'; } push(@frags,$line); return(@frags); }