while () { my ($time, $switch) = split "\t"; if ($switch eq $last) { $output[-1] = $_; } else { push @output, $_; $last = $switch; } }