in reply to BEGIN, eval {} and $^S

You want something like:
sub in_eval { my $i=0; while (my @caller=caller($i++)) { return defined $caller[6] ? "eval EXPR" : "eval BLOCK" if !$caller[7] && $caller[3] eq "(eval)" } } ... die @_ if defined $^S ? $^S : in_eval;
See perldoc caller for explanation. (I seem to recall there may be times when $^S is inaccurate; if so, just use die @_ if in_eval.)