#!/usr/local/bin/perl
use strict;
use warnings;
{
package Animal;
sub new { bless {}, shift }
package Cat;
use base 'Animal'; # inherits new()
sub speak { print "meow!\n" }
package Dog;
use base 'Animal'; # inherits new()
sub speak { print "woof!\n" }
}
$_->speak for map { $_->new } qw/Cat Dog/;
speak $_ for map { new $_ } qw/Cat Dog/;