The #line technique you are trying to use is best used with the string form of eval (eval EXPR, not eval BLOCK). What you have should work in the eval, but the #line setting will continue even after the end of the eval. Do you really need to fool perl within the eval BLOCK? It should correctly report the actual file name and line number.