You need to provide more context, but I suspect you are trying to parse one line at a time, but match strings that span several lines.

I strongly suggest that you use a module such as XML::Twig to parse XML! Consider:

use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new (twig_roots => {content => \&contents}); my $xml = do {local $/; <DATA>}; $twig->parse ($xml); sub contents { my ($twig, $contents) = @_; my @children = $contents->children (); my @wanted = qw(id title published); my $match = join '|', @wanted; my %params; for my $child (grep {$_->tag () =~ /^($match)$/} @children) { $params{$child->tag ()} = $child->text (); } print join "\t", @params{@wanted}; } __DATA__ <data> <content> <id>http://gdata.youtube.com/feeds/api/videos/5InqyMvRZ8o/comm +ents/7307D6E7F6E2D1B8 </id> <published>2007-04-05T12:05:42.000-07:00 </published> <updated>2007-04-05T12:05:42.000-07:00 </updated> <category scheme='http://schemas.google.com/g/2005#kind' term= +'http://gdata.youtube.com/schemas/2007#comment'/> <title type='text'>Fantastisk video,, ... </title> Keep up the good work. - jeg glder mig meget til at se flere +videoer fra dig..uper billeder du har fundet (: </content> <link rel='related' type='application/atom+xml' href='http://gdata +.youtube.com/feeds/api/videos/5InqyMvRZ8o'/> <link rel='alternate' type='text/html' href='http://www.youtube.co +m/watch?v=5InqyMvRZ8o'/> <link rel='self' type='application/atom+xml' href='http://gdata.yo +utube.com/feeds/api/videos/5InqyMvRZ8o/comments/7307D6E7F6E2D1B8'/> <author> <name>cajaneil </name> <uri>http://gdata.youtube.com/feeds/api/users/cajaneil </uri> </author> </data>

Prints:

http://gdata.youtube.com/feeds/api/videos/5InqyMvRZ8o/comments/7307D6E +7F6E2D1B8 Fantastisk video,, ... 2007-04-05T12:05:42.000-07:00

Note that I altered the XML to make it valid and that I chose elements that exist as children of content for demonstration purposes. You will need to alter the code to suit what you are actually doing.


Perl is environmentally friendly - it saves trees

In reply to Re: trouble with regular expressions, dont know why patters aren't matching by GrandFather
in thread trouble with regular expressions, dont know why patters aren't matching by downer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.