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;