You could use Perl's internal format defintions. Here's an example that should work for you.
#!/usr/bin/perl -w use strict; # Define various fields that we use in the format my $name = "TMH"; my $title = "PerlMonk"; my $story = 'The Mad Hatter (TMH) was a crazy monk. It was thought' . ' to be due to the mercury used to get rid of the dust ' . 'on hats...'; # This is the key part. A format is a series of fieldlines and # valuelines. Fieldlines define what the format looks like, valueline +s # specify what datagoes in the fields. Fields that start with @ are # fixed character widthfields. The < specifies that it is # left-justified. | (centered) and > (right-justified) are also # valid. The number of those specifiers is the width of the field. # The ^ is a filled field; it breaks text up (at word boundries) into # conveniently sized lines. The double tilde (~) at the beginning of # the third line specifies that the line should expand dynamically. # This allows the filled field to take up as many lines of that size a +s # it needs to. We use the format name STDOUT so that the format # affects that filehandle. format STDOUT = @<<<<<< @<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<< $name, $title, $story ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<< $story . # Print doesn't work with formats, so write must be used. write # defaults to sending to STDOUT and looks for the format STDOUT. write;
That prints
TMH PerlMonk The Mad Hatter (TMH) was a crazy monk. It was thought to be due to the mercury used to get rid of the dust on hats...
Added new code. Now with comments! ;-)

In reply to Re: format by The Mad Hatter
in thread Multi-line output with format by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.