#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Test::More qw(no_plan); $Data::Dumper::Deparse = 1; # I needed to add this my $subroutine = sub { print "test" }; print Dumper($subroutine); #nah, this just gives "$VAR1 = sub { "DUMMY" };" my $wanted = 'print "test"'; my $got = get_code($subroutine); is($got, $wanted); sub get_code { defined(my $coderef = shift) or die "no code ref"; return "whatever"; }