open (RULE, "$rulefile") || die "Can't open $rulefile for reading $!\n"; while ( defined ($_ = ) ) { if (/RULE=$rule/../^END$/) { chomp $_; if ($_ =~ /^NUMOFRULES/) { # Get the number of rules @rulenos = split(/=/); } for ($i = 1; $i <= $rulenos[1]; $i++) { if (/^STMT$i=BEGIN$/../^STMT$i=END$/) { if ( !($_ =~/^STMT/)) { print $_; } } } } } -Getting- A A B B C C ... -Want to get- A B C ...