sub FetchUserInfo { my ($dbh, $key, $userId) = @_; my $sql = "SELECT " . join(", ", @wantedColumns) . " FROM users WHERE $key=?~; .... my $dataHRef = $sth->fetchrow_hashref(); ... return $dataHRef; } my $userInfo = &FetchUserInfo($dbh, id => $userId); $template->param( %GlobalConfig, %LocalConfig, %$dataHRef);