my $flag = 0; while( ) { if ( /test/ ) { print; $flag = 1; } elsif ( $flag ) { print; $flag = 0; } }