foreach $item (@{$clusters}) { $ID = $units[$i][0]; $query = "select * from finalLevel3 where id=\"$ID\";"; $sth = $dbh -> prepare($query); $sth -> execute; @row = $sth -> fetchrow_array; # convert the mysql result back to a string again $promoter_line = join "\t", @row; $promoter_line .= "\n"; $parser_hash{$item} .= $promoter_line; $i++; }