You say don't want to replace the .* at the end with \S+, because the last column could contain arbitrary columns. However, that's not a problem for the first column, so you can replace the .+:
my ($ptid, $total, $used, $avail, $pct, $mp) = $element =~ m!^(/dev/\S+) # which partition $ptid \s+([\d.]+[MGK]) # total size of parition $total \s+([\d.]+[MGK]) # used space $used \s+([\d.]+[MGK]) # available space $avail \s+(\d{1,3})% # percent usage $pct \s+(.*)$!x; # mounting point $mp
This will save the regex engine from having to match to the end of the line and then backtrack all the way back to the first column. I also changed 0-9 to \d in the character classes, and changed \d{2} to \d{1,3}, assuming you don't really want to ignore devices that are 100% full or less than 10% full.

BTW, your regex isn't compatible across Unix platforms:

Filesystem Type blocks use avail %use Mounted on /dev/root xfs 16718720 11050536 5668184 67 / /dev/dsk/dks1d6s0 xfs 8758624 1968528 6790096 23 /usr/darmo +k AFS afs 14400000 0 14400000 0 /afs

Anyway, I think tilly's and lemming's suggestion of using split with a limit is the best approach.


In reply to Re: Getting rid of (.*) from a not-quite-complex regex. by chipmunk
in thread Getting rid of (.*) from a not-quite-complex regex. by deprecated

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.