$columns = join ',', # paste them together separated by commas map { $db->quote($fd{$_}) } # extract the value and quote it grep { exists $fd{$_} } # keep only the checked ones ('chk1'..'chk6') # Checkboxes ;