An object is polymorphic when its specific type may vary.
The types a specific value may take, is called class.

It is trivial to copy an object if its type is known:

int x;
int y = x;
Here x is not polymorphic, so y is declared of same type (int) as x.
But if the specific type of x were unknown, then y could not be declared of any specific type.

The task: let a polymorphic object contain an instance of some specific type S derived from a type T.
The type T is known.
The type S is possibly unknown until run time.
The objective is to create an exact copy of such polymorphic object (not to create a reference, nor a pointer to).
Let further the type T have a method overridden by S.
This method is to be called on the copy to demonstrate that the specific type of the copy is indeed S.

package T;
sub new {
        my $cls = shift;
        bless [ @_ ], $cls
}
 
sub set_data {
        my $self = shift;
        @$self = @_;
}
 
sub copy {
        my $self = shift;
        bless [ @$self ], ref $self;
}
 
sub manifest {
        my $self = shift;
        print "type T, content: @$self\n\n";
}
 
package S;
our @ISA = 'T';
# S is inheriting from T.
# 'manifest' method is overriden, while 'new', 'copy' and
# 'set_data' are all inherited.
sub manifest {
        my $self = shift;
        print "type S, content: @$self\n\n";
}
 
package main;
 
print "# creating \$t as a T\n";
my $t = T->new('abc');
$t->manifest;
 
print "# creating \$s as an S\n";
my $s = S->new('SPQR');
$s->manifest;
 
print "# make var \$x as a copy of \$t\n";
my $x = $t->copy;
$x->manifest;
 
print "# now as a copy of \$s\n";
$x = $s->copy;
$x->manifest;
 
print "# show that this copy is indeed a separate entity\n";
$x->set_data('totally different');
print "\$x is: ";
$x->manifest;