If your "arbitrary number of spaces" is at least two, and your second element never contains two consecutive spaces, you're well on your way.

my $string = "122 Genesis Chamber Mark Tedin A U "; my ( $second ) = $string =~ m/\s{2,}(.+?)\s{2,}/; print "$second\n";

That works if, as I stated, you are sure that the second field is surrounded by at least two whitespace characters.

Update: I want to point out that I specifically avoided the intense temptation to use unpack for two reasons: First, though the thought crossed my mind that this might be a dataset with aligned columns (fixed-width fields), the OP didn't specify that to be the case, and so since I had to make some assumption about the data, I chose the two-or-more space delimiter assumption rather than the fixed-width field assumption. My second reason was that the OP asked to solve the problem with a regexp, unpack wasn't on the table.

However, if it turns out that we are dealing with fixed-width fields, the regexp solution is simply the wrong tool for the job, and unpack is the right tool. My advice to the OP is to use the unpack solution if the data is in a fixed-width field format, or to consider one of the regexp solutions provided if the data's format is non-fixed-width.


Dave


In reply to Re: Abritrary multiple spaces as delimiter by davido
in thread Abritrary multiple spaces as delimiter by Weisshaupt

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.