require Data::Dumper if $^P; #...lots of code... my %output; ### The information that was output last my %current; ### The current record's information my %previous; ### The previous record's information ### Now that these variables are in scope, create a closure ### that we can use for debugging. This prints all 3 stacks. my $stack = sub { print Data::Dumper->Dump( [\%previous, \%output, \%current], ['*previous', '*output', '*current'] ); };