my @table_to_hash = ( [ "ConfigData", \%ConfigData ], [ "DicomDestinations", \%DestinationData ] ); for (@table_to_hash) { my ($table, $hash) = @$_; $Data->Sql("SELECT * FROM $table"); while ($Data->FetchRow ()) { my %x = $Data->DataHash(); $hash->{ $x{ID} }{ $x{DataName} } = $x{DataValue}; } }