Code:
#!/usr/bin/perl
while (<DATA>) {


 if (/\{TT\}/ .. /^\{TAG\}/)
                {
                unless (/^\{(TT|TAG)\}/)
                        {
                        $deletestrings = $_;
                        print $deletestrings;
         #      $_ = '' if index( $_, "$deletestrings" ) >= 0;
                }
        }

}
__DATA__
S 9912290449 00005941^B{TT}
D
{TAG}
9912290449
{PUBLICATION}
THE OS
{DATE}
000101

S 9912290450 00005941^B{TT}
R
{TAG}
9912290450
{DATE}
000101
{TDATE}
Saturday, January 1, 2000


S 9912290451 00005941^B{TT}
D
{TAG}
9912290451
{DATE}
000101
{TDATE}
Saturday, January 1, 2000



When I print the output is
Code:
S 9912290449 00005941^B{TT}
D
S 9912290450 00005941^B{TT}
R
S 9912290451 00005941^B{TT}
D
How to print only the lines which has D and it's above line.
Code:
S 9912290449 00005941^B{TT}
D
S 9912290451 00005941^B{TT}
D