my $previous_line; LINE: while (my $line = <>) { next LINE if $line =~ m/disregard this line/; chomp $line; # Here's where you implement your algorithm # to compare the value on line $line with the # value on line $previous_line and print the # appropriate ouput line $previous_line = $line; } # Here's where you print the last line # modified as appropriate given that # there is no next line