Say I have a file as follwing

```
myCategory1
skip some lines from reading
things that I want in the hash for myCategory2
things that I want in the hash for myCategory2
...
myCategory2
skip some lines from reading
things that I want in the hash for myCategory3
things that I want in the hash for myCategory3
...
myCategory3
skip some lines from reading
things that I want in the hash for myCategory1
things that I want in the hash for myCategory1
...

```

Now, I read the file with filehandle. The code in pseudo-format.

```
while(my $line=<FHIN>){
  chomp($line);
  if($line=~ /^myCategory1$/){
    $line=<FHIN>;           # get rid of unwanted line
    chomp($line);
    $line=<FHIN>;           # get rid of unwanted line
    chomp($line);
    $line=<FHIN>;           # this is the line of interest
    chomp($line);
    do{
      @sub_str = split(' ',$line);
      $temp_key=$sub_str[2].$sub_str[5].$sub_str[6]; #dummy assignment
      $hash{$temp_key}=$sub_str[1]; #dummy assignment
      $line=<FHIN>;         # this line cotains r.*
      chomp($line);
    }while((defined($line))&&($line !~ /^myCategory2*$/));

  }
  if($line=~ /^myCategory2$/){
    $line=<FHIN>;           # get rid of unwanted line
    chomp($line);
    $line=<FHIN>;           # get rid of unwanted line
    chomp($line);
    $line=<FHIN>;           # this is the line of interest
    chomp($line);
    do{
      @sub_str = split(' ',$line);
      $temp_key=$sub_str[2].$sub_str[5].$sub_str[6]; #dummy assignment
      $hash{$temp_key}=$sub_str[1]; #dummy assignment
      $line=<FHIN>;         # this line cotains r.*
      chomp($line);
    }while((defined($line))&&($line !~ /^myCategory3*$/));

  }
}

```

The idea is to look for Category1.....3 and capture the in between lines for further processing. Now, if I have 10 files to process each having 50 categories, according to my code, I will need 1 while loops each having 50 if..else blocks for each file, completely hard coded. How do I generalize/reduce the number of lines in my codes, that do exactly the same thing. If my question is not clear, feel free to ask!
Thanks.

**EDIT**
Thanks for the answers. Let me rephrase on what I need. 

1. Every line of file does not contain "myCategory\*"
2. There is a pattern to grep for "myCategory\*"
3. I want to catch the lines that lies within two consecutive "myCategory\*". So, for example, @Category\_1 will have all the lines between "myCategory1" and "myCategory2"
4. How should I approach if I read the entire file into a single array and then operate based on categories.