die "Usage: SegregatePod filename\n" unless @ARGV == 1; open INPUT, $ARGV[0] or die "Unable to open $ARGV[0]: $!\n"; my @paragraphs = do {local $/ = ""; }; close INPUT; my $inside_pod = 0; my $extracted_pod = ''; my $leftover_code = ''; foreach my $this_paragraph (@paragraphs) { if (substr($this_paragraph,0,4) eq '=cut') { $inside_pod = 0; $this_paragraph = ''; # =cut no longer needed since POD sections will be contiguous } elsif (substr($this_paragraph,0,1) eq '=') { $inside_pod = 1; } if ($inside_pod) { $extracted_pod .= $this_paragraph; } else { $leftover_code .= $this_paragraph; } } print "$leftover_code\n$extracted_pod\n";