# Presumably you have 6 packages listed in this list for my $package (qw( XYZ::ABC::Scalar )) { $package =~ /(Scalar|Array|Hash)(::NoLock)?/ or die "Tie type of '$package' not understood"; my $kind = $1; my $nolock = $2; no strict 'refs'; *{$package . uc("::TIE$kind")} = sub { my $class = shift; my $ssh = shift; # Scalar/Hash/Array return bless $ssh, $class; }; # These two do nothing. *{"$package\::DESTROY"} = sub {}; *{"$package\::UNTIE"} = sub {}; # And now the rest. my @functions = qw(FETCH STORE); if ($kind eq "Array") { push @functions, qw( FETCHSIZE STORESIZE EXTEND CLEAR POP PUSH SHIFT UNSHIFT SPLICE ); } elsif ($kind eq "Hash") { push @functions, qw( STORE DELETE CLEAR EXISTS FIRSTKEY NEXTKEY SCALAR ); } for my $function (@functions) { my $subname = join "_", ($nolock ? "abca" : "abc"), lc($kind) . lc($function); *{"$package\::$function"} = \&$subname; } }