in reply to Clarification on greediness

Make it step by step:

$str = join '' => <DATA>; @arr = map { m!(<first>.*?</first>)!si } # extract first grep { m!<content>maps</content>!si } # filter by content $str =~ m!<contentmodel>(.*?)</contentmodel>!gsi; # split on c +ontentmodel print @arr; __DATA__ <pages> <contentmodel> <level>5</level> <first>35</first> <content>some text</content> </contentmodel> <contentmodel> <level>4</level> <first>45</first> <content>some text</content> </contentmodel> <contentmodel> <level>3</level> <first>25</first> <content>maps</content> </contentmodel> <contentmodel> <level>2</level> <first>15</first> <content>some text</content> </contentmodel> </pages>