Suggestions above do work just fine. I made one small addition, if your are on Perl 5.10 you can use the // operator. This sets a default value of "no match" as shown below if say $4 is undefined. There aren't any write statements below so you shouldn't get your reported error anymore. You will however start getting print of undefined value warnings which the "//" avoids.
#!/usr/bin/perl -w
use strict;
open (FILE,"abc345.txt") or die $!;
while (<FILE>){
$_ =~ /((^Query = .*)|(^\>.*)|(Length = .*))/i;
print $1 // "no match", "\n";
print $2 // "no match", "\n";
print $3 // "no match", "\n";
print $4 // "no match", "\n";
}
close (FILE) ;
For data line of: Query = 345, prints:
Query = 345
Query = 345
no match
no match
Update: Had wrong file handle above in "while (<FILE>)". I used <DATA> to test my code and that didn't get corrected in the original post. Anyway the above code does run on my AS Perl 5.10.X machine. I had thought that perhaps something weird was happening with the "=" as that does have significance in a regex, but only in combination with for example "?=". Result is that you do not have to "escape" the = sign. Above code is fine. An escape "\" is required for these characters: {}[]()^$.|*+?\ |