#!/usr/bin/perl use strict; use warnings; my $var = "this is just a sample of a string, there is nothing really important in the scalar, just a lot of text"; my @box = split(/\b/, $var); my @line; while (@box) { shrink(); } sub shrink { my $word = ''; while (length $word <= 10) { last unless (@box); $word .= shift @box; } push (@line, $word); } print join("\n", @line), "\n";