Some guesses:

You didn't anchor your regexes like in the grep example, they only need to match at the start /^0\.0\.0\.0/ , the other regex to exclude comments is obsolet then.

And use chomp not an (again unachored) regex to strip newlines.

I might also try to use a while (my $line = <$in> ){...} loop instead of for , but you need to do something like open my $in ,"<", \$got; beforehand.

Perl might still be slower, because it needs more time for start up and compiling*.

(all code untested)

PS: there are more advanced tricks possible in this specific case, but you want to learn Perl and I don't wanna exaggerate it.

update

the substitution $_ =~ s/0\.0\.0\.0 //; doesn't make sense if you match the remaining of the line right away

if (/^\Q0.0.0.0\E (.*)$/) { print "<<<$1>>>"; }

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

*) especially LWP::Simple! For a fair comparison try to pipe in curl.


In reply to Re: Making this script process 56,000 lines 5 times faster by LanX
in thread Making this script process 56,000 lines 5 times faster by kris004

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.