eval { $function_name->(); }; if ( my $e = $@ ) { # Just pretend that __FILE__ interpolates. if ( $e =~ /Undefined subroutine .+ called at if ( $e =~ /Undefined subroutine .+ called at __FILE__ line 2\./ ) { # Trap only this one error ... } else { # Rethrow the error die $e; } }