use warnings; use strict; use constant kMaxGap => 7; my %gappyData; /^(\d+)\s+(\d+)/ and $2 != 0 and $gappyData{$1} = $2 while ; my $lastx; my $lasty; for (sort {$a <=> $b} keys %gappyData) { next if ! defined $lastx; next if ! defined $lasty; my $gap = $_ - $lastx - 1; next if $gap == 1; next if $gap > kMaxGap; next if $gappyData{$_} != $lasty; $gappyData{$_} = $lasty for $lastx .. $_; } continue { $lastx = $_; $lasty = $gappyData{$_}; } for (1 .. $lastx) { if (defined $gappyData{$_}) { print "$_, $gappyData{$_}\n"; } else { print "$_, -\n"; } } __DATA__ 1 2 2 3 3 3 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 3 12 0 13 0 14 4