in reply to Writing a new file in Perl

There's a lot about this that could be improved, but here's your specific problem:

while(/hops(.+)Trace/mg){ print $1, "\n" if /($RE{net}{IPv4})/;
Your while loop grabs the text between "hops" and "Trace", which includes the whole output of a traceroute. The second line searches that for an IPv4 address, and if one is found, prints it. It only searches once, so only one will be found. To make it search repeatedly, you need to give it the 'g' modifier, and put it in a loop:

print "$1\n" for /($RE{net}{IPv4})/g;

Aaron B.
Available for small or large Perl jobs; see my home node.

Replies are listed 'Best First'.
Re^2: Writing a new file in Perl
by maheshkumar (Sexton) on Jul 07, 2012 at 20:36 UTC

    Is it possible that each trace route is separated by some kind of word or something so that when I am processing them they can differentiated from one another. Actually I am mapping them, therefore they need to be differentiated from each other.

      Well, we can't tell you that without seeing a sample file with more than one traceroute in it. But I suspect you could split the records on something, yes. For instance, splitting your file on the string "Tracing route to" looks like it would probably break the file into chunks containing no more than one trace each.

      Aaron B.
      Available for small or large Perl jobs; see my home node.