use strict; use warnings; use Data::Dumper; my $obj = bless {this => 1, that => 1}; my $fileStr; open my $out, '>', \$fileStr; (my $dumpData = Data::Dumper::Dumper($obj)) =~ s/^\$\w+\s*=\s*(bless\(.*\))/$1/sm; print $out $dumpData; close $out; open my $in, '<', \$fileStr; my $str = do {local $/; <$in>}; close $in; my $newObj = eval $str; $obj->doIt (); $newObj->doIt (); sub doIt { my ($self) = @_; print "$self->{this} + $self->{that} = @{[$self->{this} + $self->{that}]}\n"; } #### 1 + 1 = 2 1 + 1 = 2