#!/usr/bin/perl # http://perlmonks.org/?node_id=1192327 use strict; use warnings; print /^Fruit(?:\{|s\{(?: \w+)+) \w+ \}$/ ? 'Pass ' : 'Fail ', $_ while ; __DATA__ Fruits{ Apple Mango Grape Watermelon } Fruit{ Apple } Fruits{ Lemon Mandarin }{ Orange Fig Pineapple } Vegetable{ Carrot } who knows{ what } you expect here