included from a line 2: included from b line 5: error in err: Bareword "z" not allowed while "strict subs" in use at err line 25. #### included from a: included from b: included from err: Bareword "z" not allowed while "strict subs" in use at err line 25. #### package L; sub include { my $f = shift; my $r = do $f; unless (defined $r) { die "included from $f:\n$@" if $@; } } 1; #### use L; ... L::include "a"; ... L::include "b"; #### error loading 'ERR': Bareword "z" not allowed while "strict subs" in use at ERR line 5. stack trace: L::include called at D line 1 L::include called at C line 1 L::include called at B line 11 L::bar called at B line 7 L::foo called at B line 14 L::include called at A line 2 #### package L; use warnings; use strict; use File::Slurp; sub include { my ($f) = @_; eval { my $e = eval qq(#line 1 "$f"\n) . read_file $f; die $@ if $@; }; if ($@) { die $@ if ref($@) ne '' or $@ =~ /stack trace:/s; my $max_depth = 30; my $err = "error loading '$f': $@stack trace:\n"; my $e = -1; my @stack; my $i; for ($i = 0 ; $i < $max_depth ; ++$i) { my ($package, $filename, $line, $subroutine) = caller($i); last unless $package; # removing two evals below every include splice(@stack, -2, 2) if @stack > 2 and $subroutine eq "L::include"; push(@stack, " $subroutine called at $filename line $line"); } $err .= join("\n", @stack, ""); $err .= "...\n" if $i == $max_depth; die $err; } } 1;