my %hash = ( username => $form_username, password => $form_password, name => $form_name, ); # was trying to do this with map ... but time is short ;) for (keys %hash) { delete $hash{$_} unless $hash{$_}; } my $sql = 'select from table where ' . join(' and ', map { qq|$_ = "$hash{$_}"| } keys %hash);