use Carp; our $testcount; BEGIN{#count number of tests dynamically eval{ my $file = "/some_dir/t/test.pl"; open(F, $file) || croak "can't open ***file:$file*** error:$!"; my @f = grep {/ok\(|is\(|like\(/gis} ; close F; $testcount = @f; }; if($@){ warn qq|ThrowError:$@|; } } use Test::More tests => $testcount; #{...}#remaining test code