in reply to Best way to compare my data?

I understand, that you need a hop- and section-wise comparison, so the following might get you started. However, the naive - text based - approach below will fail when the order of hops/IP's changes - e.g. by means of topology changes or selection of an alternative route having more/less intermediate hops. IF that is also of concern to you, a real network model (nodes and edges (graphs)) would be better suited than a plain text comparison. HTH

IP#1 IP#2/2b IP#3 IP#4 Section D +iff ============================================ +================== OK (alternate route): HOP1 --- HOP2 ----------- HOP3 (#1) HOP1 --- HOP2b ----------- HOP3 (#2) --> +@hop2: IP#2-->IP#2b EEK! (non-equidistant): HOP1 --- HOP2 ----------- HOP3 (#1) a) shorter route HOP1 --------------------- HOP2 (#2a) --> +@hop2: IP#2-->IP#4 (err?) b) longer route HOP1 --- HOP2 --- HOP3 --- HOP4 (#2b) --> +@hop3: IP#4-->IP#3 (err?)

use strict; use warnings; sub prettyip { my $ip = shift; $ip =~ s/ (\d+) / sprintf("%03d",$1) /smgex; return $ip; } my %last_seen_ip_from_hop; # last IP seen for key=HOP my $section = 1; # section within the file my $previous_hop = 0; # previous HOP / new section event while (my $line = <DATA>) { if ($line =~ /^(\d+),(\S+)/) { # extract HOP and IP my ($hop, $ip) = ($1, $2); my $last_ip_seen = $last_seen_ip_from_hop{$hop}; my ($changemark_pre, $changemark_pos) = ("", ""); # detect a new section (A/B/C) $section++, print "\n" if $previous_hop > $hop; # new file/section $previous_hop = $hop; # notify if a change occured for a given hop since last seen if (defined $last_ip_seen and $ip ne $last_ip_seen) { $changemark_pre = 'changed to'; $changemark_pos = '(was: ' . prettyip($last_ip_seen) . ')'; } $last_seen_ip_from_hop{$hop} = $ip; # init or update current HOP/I +P printf "sect.%2d / hop %2d: %15s %15s %s\n", $section, $hop, $changemark_pre, prettyip($ip), $changemark_pos; } } __DATA__ 13,4.69.137.70 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.75 19,4.59.0.10 20,124.211.34.129 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.74 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.11 19,4.59.0.10 20,124.211.34.121 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.70 14,4.69.134.78 15,4.69.134.125 16,4.69.135.185 17,4.69.134.250 18,4.68.18.139 19,4.59.0.10 20,124.211.34.121 21,203.181.100.189 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11
Output:
sect. 1 / hop 13: 004.069.137.070 sect. 1 / hop 14: 004.069.134.070 sect. 1 / hop 15: 004.069.134.113 sect. 1 / hop 16: 004.069.135.185 sect. 1 / hop 17: 004.069.134.246 sect. 1 / hop 18: 004.068.018.075 sect. 1 / hop 19: 004.059.000.010 sect. 1 / hop 20: 124.211.034.129 sect. 1 / hop 21: 203.181.100.061 sect. 1 / hop 22: 118.155.197.140 sect. 1 / hop 23: 124.211.010.066 sect. 1 / hop 24: 163.139.130.138 sect. 1 / hop 25: 163.139.124.057 sect. 1 / hop 26: 202.215.179.001 sect. 1 / hop 27: 202.215.179.011 sect. 2 / hop 13: changed to 004.069.137.074 (was: 004.069.137.07 +0) sect. 2 / hop 14: 004.069.134.070 sect. 2 / hop 15: 004.069.134.113 sect. 2 / hop 16: 004.069.135.185 sect. 2 / hop 17: 004.069.134.246 sect. 2 / hop 18: changed to 004.068.018.011 (was: 004.068.018.07 +5) sect. 2 / hop 19: 004.059.000.010 sect. 2 / hop 20: changed to 124.211.034.121 (was: 124.211.034.12 +9) sect. 2 / hop 21: 203.181.100.061 sect. 2 / hop 22: 118.155.197.140 sect. 2 / hop 23: 124.211.010.066 sect. 2 / hop 24: 163.139.130.138 sect. 2 / hop 25: 163.139.124.057 sect. 2 / hop 26: 202.215.179.001 sect. 2 / hop 27: 202.215.179.011 sect. 3 / hop 13: changed to 004.069.137.070 (was: 004.069.137.07 +4) sect. 3 / hop 14: changed to 004.069.134.078 (was: 004.069.134.07 +0) sect. 3 / hop 15: changed to 004.069.134.125 (was: 004.069.134.11 +3) sect. 3 / hop 16: 004.069.135.185 sect. 3 / hop 17: changed to 004.069.134.250 (was: 004.069.134.24 +6) sect. 3 / hop 18: changed to 004.068.018.139 (was: 004.068.018.01 +1) sect. 3 / hop 19: 004.059.000.010 sect. 3 / hop 20: 124.211.034.121 sect. 3 / hop 21: changed to 203.181.100.189 (was: 203.181.100.06 +1) sect. 3 / hop 22: 118.155.197.140 sect. 3 / hop 23: 124.211.010.066 sect. 3 / hop 24: 163.139.130.138 sect. 3 / hop 25: 163.139.124.057 sect. 3 / hop 26: 202.215.179.001 sect. 3 / hop 27: 202.215.179.011