my $i; for ($i = 0; $i <@array; $i++) { if($array[$i] =~ /^Count\:\s /) { $Count_Name = $1; for ($count = $i; $count >= 1; $count--) { if ($array[$count] =~ /ID:\s*(.+)/ ) { $ID = $1; my $Mycell1 = $Sheet->Range($Sheet->Cells($row, $col),$Sheet->Cells($row, $col+2)); $Mycell1->{Value}=["Count_Name","$ID"]; $row++; # print $out_fh $sdd."\t".$Fun."\t".$File."\n"; goto breakingfunction; } } breakingfunction: } } }