Regular expression help in perl

Hi all,

I am trying to match a multi line string and return the matching string in one line. Here is the perl code that I wrote:

#!/usr/bin/perl
my $str='<title>My
title</title>';

if ($str =~ /(<title>)([^<]+)(<\/title>)/ ){
print "$2\n";
}

It returns :

My
title

I want the regex to return it in a single line as : My title

What should be the regex for this? Is it possible to do it using regex only? I want this capabilty through regex only.

Thanks

Sandeep

Why only with one regexp? Assign $2 to a modifiable scalar and remove the newlines/carraige returns.

#!/usr/bin/perl
my $str='<title>My
title</title>';

if ($str =~ /(<title>)([^<]+)(<\/title>)/ ){
   my $r = $2;
   $r =~ /[\r\n]//g;
   print $r;
}

Thanks for the reply.

The regex feeds to a program to extract the data from the net. So I need the capabilty in the regex if possible. If this is impossible in a regex, then I need to modify my extraction program to replace new line character.

Thanks

I don't know how to do it with one regexp.