Short code, using a (relatively) complex regex with negative look-ahead for the special case "unassigned":
use strict; use warnings; local $/="\narray "; while (<DATA>){ s/\n(?!unassigned)(:?array)?/ /g; print my $row=(m/^array/?"":"array "). "$_\n"; } __DATA__ array A physicaldrive 2C:1:1 port 2C:box 1:bay 1 SAS 1 TB OK physicaldrive 2C:1:2 port 2C:box 1:bay 2 SAS 1 TB OK array B ... etc ... unassigned physicaldrive 7C:3:7 port 7C:box 3:bay 7 SAS 1 TB OK ...
Output :
array A physicaldrive 2C:1:1 port 2C:box 1:bay 1 SAS 1 TB OK physicald +rive 2C:1:2 port 2C:box 1:bay 2 SAS 1 TB OK array B physicaldrive 2C:1:3 port 2C:box 1:bay 3 SAS 1 TB OK physicald +rive 2C:1:4 port 2C:box 1:bay 4 SAS 1 TB OK ... array J physicaldrive 6C:3:3 port 6C:box 3:bay 3 SAS 1 TB OK physicald +rive 6C:3:4 port 6C:box 3:bay 4 SAS 1 TB OK array K physicaldrive 7C:3:5 port 7C:box 3:bay 5 SAS 1 TB OK physicald +rive 7C:3:6 port 7C:box 3:bay 6 SAS 1 TB OK unassigned physicaldrive 7C:3:7 port 7C:box 3:bay 7 SAS 1 TB OK physic +aldrive 7C:3:8 port 7C:box 3:bay 8 SAS 1 TB OK
Separating the "unassigned" in $row is left as an exercise.

        "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams


In reply to Re: Join multiple lines in a string based on regex. by NetWallah
in thread Join multiple lines in a string based on regex. by pr33

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.