in reply to Name of subpackage dependent on main package

Well, package just doesn't take variables. You could wrap the package declaration and the methods therein into a string eval. However, apart from demonstrating that it can be done I can not imagine a problem which can't be solved in an other, more reasonable way.
use strict; use warnings; package My; use Data::Dump qw(dump); my $pkg_sub = __PACKAGE__ . '::A'; my $package_declaration = "package $pkg_sub;"; eval $package_declaration . <<'EndOfPackage'; sub new { my $class = shift; bless [@_], $class; } # some more methods EndOfPackage my $new_object = $pkg_sub->new( qw( a b c) ); dump $new_object; # prints: bless(["a", "b", "c"], "My::A") 1;
No. Don't do this.