foreach my $key (keys %defaults) { foreach my $value (@$key) { $SQLStatement =~ s/\$(\w+)/$value/eg; # then use your $SQLStatement .... } }