http://www.perlmonks.org?node_id=33646


in reply to (Debugging, Tracing, Trace, Instrumenting) Automatic tracing of my Perl code?

You may be able to wrap your script in another script that inserts the print statements for you:
my $script; while (<DATA>) { $script .= $_; $script .= qq{print "line $.\\n";\n}; } eval $script; __END__ # your script goes here
You may be able to take this on step further and place that in a package, say, 'FollowLines', and then do something like this:
use FollowLines; __DATA__ # your script goes here
Be advised, though, that multi-line constructs will break this. Consider this code:
if ($some_var == 1 || $other_var == 2 || $third_var) { sprintf("%s %s %d %s\n", $some_var, $other_var, @rest); }
A print statement every line would be a Bad Thing. I'm afraid there's not much you can do to get this functionality in a reliable fashion.