my $doc = PPI::Document->new($file); my $stmts = $doc->find('PPI::Statement'); my %layout; my @order; my $package; for (@$stmts) { if (ref $_ eq 'PPI::Statement::Package') { $package = $_->namespace; push @order, $package; } if (ref $_ eq 'PPI::Statement::Sub') { push @{ $layout{$package} }, $_->name; } } for (@order) { print "$_:\n"; for (@{ $layout{$_} }) { print "\t$_\n"; } }