I'm not entirely sure what you're trying to do. Surely, all lines in your file will be between two lines beginning with h, aside from those before the first line beginning with h, and after the last line beginning with h?
in reply to Search file for certain lines
It might make it easier to understand the problem if you give some sample data, and the result you expect to get. Have a look through this: How do I post a question effectively?
Finally, based on your question, my best guess would be something like this:
I hope that helps.
my $file = $ARGV;
my $check = 0;
@line = split('', $_);
$check += 1 if $line eq 'h';
if ($check%2 == 1)
if (($line eq 'j') || ($line eq 'E') || ($line[0
+] eq 'G'))
print STDOUT "$_";