Q:

Substitution Method - How to find two tags with a newline inbetween using Perl?

I have searched for a newline inbetween two lines in a html coding... I have tried out substitution method in perl...
Following is the coding i have tried...
File.txt
<body>
<p>God is great</p>
<p>He lives everywhere</p>
.......
</body>

Output:
file.html

<body>
<p>God is great He lives everywhere</p>
.......
</body>

Coding:
I have searched using substitution to merge the two lines...
print "Enter the filename: ";
chomp($file=<STDIN>);
open my $in,  '<', "$file.txt" or die "Can't read old file: $!";
open my $out, '>', "$file.html" or die "Can't write new file: $!";
while( <$in> )
{
s/(.+)<\/p>\n<p>/$1 /gs;
print $out $_;
}
close $in;
close $out;

But this not working
How can update this????

A:

You're reading the file one line at a time so there won't ever be a \n to match the substitution. Instead of using a while loop, you can read the file in one go:
my $html = do { local $/; <$in> };

Then do the substitution:
$html =~ s#</p>\n<p># #g;
print $out $html;

Notice I'm using an alternative delimiter for the substitution to avoid having to escape the /.

