Perl : Process a file in perl

I have a file with following data :

Qspace: COLOR: Queue: doColor
Qspace: COLOR: Queue order: fifo
Qspace: COLOR: Out of order: none
Qspace: COLOR: Retries: 5
Qspace: COLOR: Queue: setColor
Qspace: COLOR: Queue order: fifo
Qspace: COLOR: Out of order: none
Qspace: COLOR: Retries: 5
Qspace: COLOR
Qspace: MatchSpace: Queue: getColor
Qspace: MatchSpace: Queue order: fifo
Qspace: MatchSpace: Out of order: none
Qspace: MatchSpace: Retries: 10
Qspace: MatchSpace
:
:

I am looking for an output like,

Qspace: COLOR: Queue: doColor
Qspace: COLOR: Queue: doColor: Queue order: fifo
Qspace: COLOR: Queue: doColor: Out of order: none
Qspace: COLOR: Queue: doColor: Retries: 5
Qspace: COLOR: Queue: setColor
Qspace: COLOR: Queue: setColor: Queue order: fifo
Qspace: COLOR: Queue: setColor: Out of order: none
Qspace: COLOR: Queue: setColor: Retries: 5
Qspace: COLOR
Qspace: MatchSpace: Queue: getColor
Qspace: MatchSpace: Queue: getColor: Queue order: fifo
Qspace: MatchSpace: Queue: getColor: Out of order: none
Qspace: MatchSpace: Queue: getColor: Retries: 10
Qspace: MatchSpace

For each Qspace there is/are queue/s associated with it. I need to append name of each Qspace & Queue with every attribute.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Looks awfully like a double-post of this

open FH,"<a.txt";
while(<FH>){
  if(/Queue: ([^ \n]+)$/){
  print;
  $queue=$1;
  next;
}
  if(/Retries/){
  s/(COLOR|MatchSpace): /$1: Queue: $queue: /;
  print;
  undef $queue;
  next;
}
  if(/COLOR$/){
  print;
  next;
}
  s/(COLOR|MatchSpace): /$1: Queue: $queue: /;
  print;
}

Thanks summer_cherryfot the code. I am looking for a more generic form of the code. COLOR & MatchSpace has been hardcoded to get the desired result. If you can give me more generic form of the code without hardcoding any values, it will be great. (Can consider those values are values in an array.)