Thankyou all for the suggestions. It was really helpful. The following code did my task
sub getGiForZeroHits
{
my $previous1,$previous2;
open(FILEOUT,">giForZeroHits.txt") or die("Cannot open file");
{
open(FILE, "$inputSeqFileForBlast-1e-10.out") or die("Cannot open file
+");
{
while(<FILE>)
{
my $line = $_;
if($line=~/# 0 hits found/)
{
my @lineSpl = split(/\|/, $previous2);
print FILEOUT "$lineSpl[1]\n";
} #close if
$previous2= $previous1;
$previous1= $line;
} #close while
close(FILE);
} #close FILE
close(FILEOUT)
} #close FILEOUT
} #close sub