#!/usr/bin/perl use strict; use warnings; my $lastmatch = 0; while (<>) { my $match = m~ROT~; print if $match or $lastmatch;   $lastmatch = $match; }