Is the question about doing DNS lookups in Perl? In that case use an appropriate module, such as Net::DNS::Lookup, or one of the others you find by querying CPAN for 'DNS Lookup'

If your actual concern is achieving a greater understanding of regular expressions, try:

Update

You wrote:

    if ($found_addr =~ m/address(.*)\d/){ print "$1\n"; }

    But it's cutting off the last digit of the address for some reason.

Let's go back to basics and discuss this block: IF (the stuff between parentheses is true)THEN DO {the stuff between curly braces}.

the stuff between parentheses is applying a regular expression to the value stored in the variable $found_addr. The regular expression looks for the sequence of characters: 'a', 'd', 'd', 'r', 'e', 's', 's', followed by a wildcard sequence which is captured, followed by a digit which is not captured.

From our knowledge of what was being returned, we know you are capturing a space character, ' ', followed by some digits, a dot, some digits, .... Since the captured sequence is followed by a non-captured digit, the last digit will not be captured. When you look at your printout, you'll notice the IP address is one character to the right, because of the captured space.

If you want to capture the digit, put it within the capturing parentheses. If you want to exlude the space, explicitly specify it outside the parentheses.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: More complicated regular expression? by TomDLux
in thread More complicated regular expression? by jaldama

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.