my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { RaiseError => 1, }) or die $DBI::errstr; my $sth = $dbh->prepare("SELECT titles FROM tbl_1"); $sth->execute(); my $Data = $sth->fetchall_arrayref(); my %output; foreach my $Data (@$Data) { my ($title) = @$Data; %output .= ( 'items' => [("title" => "$title")] ); } my $results = to_json(\%output); print "Content-type: text/html\n\n"; print $results;