Split pod documentation from a Perl module

This Perl script splits the file name on its command line into .pm and .pod parts. The files are given a temporary name using the process number ($$).

use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use File::Slurper qw/read_text write_text/;
if (! @ARGV) {
    usage ();
for my $file (@ARGV) {
    if (! -f $file) {
        warn "No such file '$file'";
    my $text = read_text ($file);
    my $pod = '';
    while ($text =~ s!(^=(head|encoding|pod).*?)=cut$!!sm) {
        $pod .= "$1\n";
    my $podout = "$file.pod.$$";
    my $pmout = "$file.pm.$$";
    write_text ($pmout, $text);
    write_text ($podout, $pod);

sub usage
    print <<EOF;
$0 - split a Perl module into Perl and Pod files


$0 <file1> <file2>

The output is the name of the files with a random number attached.


At my blog post about this topic, commentators note that

Copyright © Ben Bullock 2009-2022. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer