#/usr/bin/perl package Foo; sub new { # ... } # other stuff if (__FILE__ eq $0) { my $foo = new Foo; # test foo's methods, etc } 1;