in reply to Re^2: how to add a PPI:Statement to a document?
in thread how to add a PPI:Statement to a document?

In fact, you also should just throw away the other document immediately.
$lastVar->insert_after( PPI::Document->new('print "Hello World!\n")->f +ind_first('Statement') );