Here is one way to get your stated desired output from your stated input...
#!/usr/bin/perl -w use strict; my $letter ='a'; while (<DATA>) { print_record(); print "\n"; # record spacer # $letter++; } # adds an alpha character to the id that's like <1> # except weirdly enough for a. # sub print_record { s/<(\d+)>/<$1$letter>/ unless $letter eq 'a'; print; while (defined($_ = <DATA>) && $_ !~ /^\s*$/) { s/<(\d+)>/<$1$letter>/ unless $letter eq 'a'; print; } } =prints: <1>66543 <2>2009 <3>TY <4>- <6> <7>TOM <8>2 - DUNDAS <8>100 - MAIN <9>ONT 00001 <10> <11>000-000-0000 <12> <1b>12345 <2b>1999 <3b>PP <4b>XLX - TEST <6b>Comm <7b> <8b>1 BLVD <9b>MA 00001 <10b>CITI, INC. <11b>000-000-0000 <12b> <1c>8887 <2c>2000 <3c> <4c>TEST <6c> <7c>JOE <7c>MARY <8c>100 MAIN <9c>CT 02221 <10c>BH, INC. <11c>871-000-0000 <12c>YEAR <1d>test <2d>2087 <3d>XX <4d>- <6d> <7d>DOM <8d>2 - CHT <8d>1000 - CAR <9d>ONTA X0001 <10d> <11d>000-000-0000 <12d> <13d> <14d>CB =cut __DATA__ <1>66543 <2>2009 <3>TY <4>- <6> <7>TOM <8>2 - DUNDAS <8>100 - MAIN <9>ONT 00001 <10> <11>000-000-0000 <12> <1>12345 <2>1999 <3>PP <4>XLX - TEST <6>Comm <7> <8>1 BLVD <9>MA 00001 <10>CITI, INC. <11>000-000-0000 <12> <1>8887 <2>2000 <3> <4>TEST <6> <7>JOE <7>MARY <8>100 MAIN <9>CT 02221 <10>BH, INC. <11>871-000-0000 <12>YEAR <1>test <2>2087 <3>XX <4>- <6> <7>DOM <8>2 - CHT <8>1000 - CAR <9>ONTA X0001 <10> <11>000-000-0000 <12> <13> <14>CB

In reply to Re: Adding an identifier to an array element. by Marshall
in thread Adding an identifier to an array element. 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.