in reply to Extract from text file

Maybe you are overwriting $1, your loop seems strange to me

while (<ISH>){ my $a; my $b = '#'; my $c; my $x; if (m/DEV_STAGE\t(.*?)\n/g) {$a= $1; print OUT "a is: ",$a} elsif (m/PREDICTED_GENE\t(.*?)\n/g){$b =$1; print OUT "b is: ",$b} elsif (m/\tSTAINED_REGION:\t(.*?)\tSTAINED_MOL:\t(.*?)\n/g) { $c = $1; print OUT "c is: ",$c; $x = $2; print OUT "x is: ",$x; } else {} }

but your real problem is probably this:

open (OUT, ">", "out.txt")

You make a first pass to the loop and print to OUT

Then you examine the second line, make a second loop and OVERWRITE the output file with the actual values, $a is lost now

Then you make a third pass and OVERWRITE AGAIN, $b is lost... etc

Solution: use '>>' instead '>' and put each print inside its own if-elsif block