7. Example IV: wrap long texts

The Text::Wrap module is used to wrap a text to the specified line length.
 
use Text::Wrap;

# Set the line length ('columns') to which the text should be wrapped
$Text::Wrap::columns = 20;

# Sample text to be wrapped
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dignissim, tortor ac cursus consequat, nisi libero eleifend dolor, id vehicula libero sapien eget risus. Aliquam a volutpat tortor.";

print( wrap("", "", $text) . "\n" );

Output:
Lorem ipsum dolor
sit amet,
consectetur
adipiscing elit.
Sed dignissim,
tortor ac cursus
consequat, nisi
libero eleifend
dolor, id vehicula
libero sapien eget
risus. Aliquam a
volutpat tortor.

With some indentation:
 
print( wrap(">>>>>", ">", $text) . "\n" );

Output:
>>>>>Lorem ipsum
>dolor sit amet,
>consectetur
>adipiscing elit.
>Sed dignissim,
>tortor ac cursus
>consequat, nisi
>libero eleifend
>dolor, id vehicula
>libero sapien eget
>risus. Aliquam a
>volutpat tortor.