sub build_sql () { my $table = shift; my %where = @_; # should use hash refs, but this is an example my $sql = "select * from $table where "; foreach (keys(%where)) { #assumes quote() defined elsewhere to escape values $sql .= "$_ = ".quote($where{$_}).','; } chop $sql; #remove trailing comma return $sql }