# called with : mkBless(\$p->{Vcpeid}{$cpeid}, RepoVData->new); sub mkBless($;$) { my $targ = shift; if (@_) { ${$targ} = shift unless blessed $targ; } \$targ } #### # notice @ params: contails optional class name and any optional params to new() sub mkBless($;@) { my $targ = shift; if (@_) { ${$targ} = shift->new(@_) unless blessed $$targ; } # you don't need to return anything, but if you must: $$targ; #\$targ } # example call: my $obj = mkBless(\$someotherobj, 'RepoVData', 1,2,3);