#!/usr/bin/perl -w use Regexp::Common qw/net/; use warnings; #use strict; use Regexp::Common qw/net/; use strict; use Cwd; my $mypath=getcwd(); my $mypath=$mypath."/sd"; my $ip; chdir $mypath; my @files = <*>; my $var=0; my $i = 0; my $traceroute; my $line; foreach (@files) { if (-f $_) { process ($_); } } sub process { my $file2 = $_[0]; open my $in, '<', $file2 or die $!; open my $out, '>', "$file2.log" or die $!; while (my $line = <$in>){ if($line =~ /^Traceroute: .* (\S+)/) { $traceroute = $1; #print "$traceroute\n"; $var++; #print "$traceroute\n"; } my ($ip) = $line =~ /(?: \d+ \s \s+) ($RE{net}{IPv4}) /msx; print "$ip\n"; if($traceroute eq $ip){ print {$out} $ip if defined ; if($ip ne undef){ {$i++;} } } else { } } print {$out} "Number of traceroutes - $var\n"; print {$out} "Number of traceroutes reached destination - $i\n"; my $subs = $var-$i; print {$out} "Number of traceroutes that did not reaach destination ($subs)\n"; my $perc = ($i/$var)*100; print {$out} "Percentage of sucessful traceroutes ($perc%)\n"; # ... your remain code here }