use warnings; use strict; my $text = "I'd like a foobar(s)! What about you?"; print "Pretext: $text\n"; my $num_of_chars = 13; $text =~ s/(.{$num_of_chars}[\w|\(.*\)\w]*).*/$1/; print $text; #### use warnings; use strict; my $text = " I'd like a foobar(s)! What about you?"; print "Pretext: $text\n"; my $num_of_words = 6; my @text; for (my $i=1; $i<=$num_of_words; $i++) { $text =~ s/^\s*([\w|\(|\)|'|:|!|\.|\,|;]*\s*)(.*)/$2/; push (@text,$1); } for (@text) { print $_; }