#!/usr/bin/perl -w use strict; my $last = ""; my $cursor = -1; my @output; while () { my ($time, $switch) = split "\t"; if ($switch eq $last) { $output[$cursor] = $_; } else { $cursor++; $output[$cursor] = $_; $last = $switch; } } foreach (@output) { print; } __DATA__ time1 UP time2 DOWN time3 UP time4 DOWN time5 DOWN time6 DOWN time7 UP time8 UP time9 UP time10 DOWN time11 UP