Align Text within <p> Tags in a HTML file.

Hi All !!!

I have an HTML file whose contents are as below:

<html>
<body>
<title>This is a test file</title>

<p>PLEASE ALIGN
ME IN ONE
LINE. TEXT....</p>

<h2>This is a Test file</h2>

<p>PLEASE ALIGN
ME IN ONE
LINE. TEXT....</p>

</body>
</html>

As you see above, the text within <p> tags is broken/scrambled in multiple lines. I want to join these lines so that text within <p> tags comes in single line throughout the html file. So my OUTPUT should be as under::

<html>
<body>
<title>This is a test file</title>

<p>PLEASE ALIGN ME IN ONE LINE. TEXT....</p>

<h2>This is a Test file</h2>

<p>PLEASE ALIGN ME IN ONE LINE. TEXT....</p>

</body>
</html>

Thanks a lot in advance!!!

#! /usr/bin/perl
undef $/;
open FH,"<file.txt";
$str=<FH>;
$str=~tr/\n/ /d;
$str=~s/(<html>)/\1\n/;
$str=~s/(<body>)/\1\n/;
$str=~s/<(.*?)>(.*?)<\/\1>/<\1>\2<\/\1>\n/g if $str!=~m/html/ || $str!=~m/body/;
$str=~s/(<\/html>)/\1\n/;
$str=~s/(<\/body>)/\1\n/;
print $str;

Or with awk:

awk '/<p>/{f=1}
/<\/p>/{print ;f=0;next}
f{printf "%s ", $0;next}
1' file

Regards