use strict; use warnings; while () { print ">$1<\n" if / ^ \s* Fruits? \s* \{ \s* (.*?) \s* \} /x; } __DATA__ Fruits{ Apple Mango Grape Watermelon } Fruit{ Apple } Fruits{ Lemon Mandarin }{ Orange Fig Pineapple } Vegetable{ Carrot }