For your table formatting, take a look at Text::Table.

Here's a quick take at some code to extract the data from your files. Take a close look at your regexes, they don't need to be substitutions, and the use of the greedy '.*' will cause you to get wrong values on lines with multiple tags.

# Assume a FIELD#...# string can't be split across lines. use strict; use warnings; use Data::Dumper; my @DATA_FIELDS = ( 'TITLE', 'DATA-A', 'DATA-B', 'DATA-C', ); # Build a regex that matches all fields and extracts a value. my $all_fields = join '|', @DATA_FIELDS; my $DATA_REGEX = qr/($all_fields)#([^#]*)#/; my @data; # store all tag data my $title_data = {}; # reference to current title's data store. while (<DATA>) { # the /g while ( /$DATA_REGEX/g ) { my $field = $1; my $value = $2; print "$_ -> $field, $value\n"; if( $field eq 'TITLE' ) { # store previous title data set if not empty. push @data, $title_data if %$title_data; # start new title data set $title_data = { TITLE => $value }; } else { # store field data in current title data set. push @{ $title_data->{$field} }, $value; } } } # store final title data set push @data, $title_data if %$title_data; print Dumper \@data; __DATA__ asdf asdfg=4eafvasdfadsf ashfasdf asdf qer qwer asd as dsasdi weeiwer dfhjTITLE#How are you#asdfads asdfa asdg rt wqrqw re DATA-A#item1#asdfdasfdasdasDATA-B#item2# asdfda dasfa asdfdas DATA-C#item3# aasdfDATA-A#item1a#DATA-B#item2b# asd asdf asdDATA-C#item3c# asdf asdf3132 adsf TITLE#I am fine#ads fadsfdasfdas


TGI says moo


In reply to Re^3: Looking for Perl Elegance! by TGI
in thread Looking for Perl Elegance! by perlNinny

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.