my @columns = join ',', map { $db->quote($fd{$_}) } grep { exists $fd{$_}} ('chk'); my $columns = split/\0/, @columns; SQL code SELECT $column