use Text::Autoformat;
my ($allTheText) = shift; ## all your text to format
my (@lins); ## your resulting lines
my ($widthTxt) = 30; ## your line width...
{
my ($formated)=autoformat($allTheText, { left=>5, right=>$widthTxt
+, all=>1}) if ($allTheText);
foreach (split(/\n+/,$formated))
{
push(@lins,$_); ## array w/lines of max.30chrs.wth.
}
}