Your match (.+) is greedy so it will match as much as possible, i.e. up to the second </year>. Make it non-greedy with the addition of a question mark.
$ perl -E ' > $var = q{<x><year>2010<day>5</day></year><month>January</month> <day +>31</day>, <year>2010</year></x>}; > say $1 if $var =~m{<year>(.+?)</year>};' 2010<day>5</day> $
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: pattern match of first occurance
by johngg
in thread pattern match of first occurance
by Selvakumar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |