This may be something like what you want. It's usually best for maintainability and comprehensibility to build up complex regexes from simpler components. And then there's also Regexp::Common (see esp. Regexp::Common::net).

c:\@Work\Perl\monks>perl -wMstrict -le "my $octet = qr{ 25 [0-5] | 2 [0-4] \d | [01]? \d [0-9]? }xms; my $ip = qr{ (?<! \d) $octet (?: \. $octet){3} (?! \d) }xms; my $addr = qr{ $ip / \d{1,2} (?! \d) }xms; ;; my $s = 'x 0.0.0.0/0 y 1.23.234.1/1 z 255.25.2.2/99 ' . '9999.9.9.999/1 z 9.9.9.9/999' ; ;; my @addrs = $s =~ m{ $addr }xmsg; printf qq{'$_' } for @addrs; print ''; ;; ;; use Regexp::Common qw(net); ;; my @common = $s =~ m{ (?<! \d) $RE{net}{IPv4} / \d{1,2} (?! \d) }xmsg +; printf qq{'$_' } for @common; " '0.0.0.0/0' '1.23.234.1/1' '255.25.2.2/99' '0.0.0.0/0' '1.23.234.1/1' '255.25.2.2/99'

Update: Added Regexp::Common::net example.


In reply to Re: Section of $string into new array by AnomalousMonk
in thread Section of $string into new array by GeorgMN

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.