my $length = 20; # Sample length text area line while ($textData =~ s/(.{$length})/$1\n/gcs) {}