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 } #### 17:48 >perl 1784_SoPW.pl >Apple Mango Grape Watermelon< >Apple< >Lemon Mandarin< 17:48 >