my @block; while ( <$fh> ) { if ( /^\#/ ) { if ( $block[3] =~ /^ord\s*$/ ) { print $block[0]; } $#block = -1; } push @block, $_; }