If you truly mean to have overlapping fields, I don't think unpack would work, but substr or a lookahead regex would:

substr: Note that second parameter is 0-based. A warning will be given if the start position is beyond (but not at!) the end of the string; the result will be shorter than the requested length if $in isn't long enough.

$one = substr($in, 23, 15); $two = substr($in, 28, 10);
Beware! If you use substr in an lvalue context, the warning gets promoted to an error:
$ perl -we'sub foo { print $_[0] } eval { foo(substr "abc", 4, 1); 1} +or die "croak: $@"' croak: substr outside of string at -e line 1.
regex: use one (?=) anchored at the beginning per field. The offsets are still 0-based.
$in =~ /^ (?=.{23}(.{15})) # field one (?=.{28}(.{10})) # field two /xs or warn "bad input: $in ";
If columns may be shorter, use .{0,15} and .{0,10} or similar. If a starting column is beyond the end of the string, the regex will fail.

In reply to Re: reading in fixed width by ysth
in thread reading in fixed width by meisterperl

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.