use 5.010; use Text::Wrap qw(wrap $columns); our $columns = 57; # change this my $hbar = q{-} x ($columns + 12); # DON'T change this printf "%s\n| TITLE |%-${columns}s| %s\n| AUTHOR |%-${columns}s| %s\n| DATE |%-${columns}s| %s\n| CONTENT |%-${columns}s| %s\n", map({ if (/\n/) { s{^(.*)\K\n} { sprintf("%*s\n|", $columns - length($1), '|'). q{ } x (length($hbar)-$columns-3). q{| } }egm; s{\n\|\h+\|(.*)\K\z} { sprintf '%*s', $columns - length($1), q{ } }e; s{\A(.*)\K\|$}{length($1)<$columns ? q{ |} : q{|}}em; } $_ } map({$hbar, q{ } . wrap(q{}, q{}, $_)} $title, $author, $date, $content),$hbar);