I found this great post on perlmonks.org that talked about how to change a subroutine at runtime. So here is the code example that changes a sub routine at runtime.
use B::Deparse;
my $sr = sub { print “Hello\n” };
$sr->();
my $c = B::Deparse->new->coderef2text($sr);
$c =~ s/print\s\S+/die “Bye”;/;
$sr = eval “sub $c”;
$sr->();