Turn POD into Readable Terminal Text with pod2text
You will convert a Perl POD file, or documentation embedded in a Perl source file, into plain text that is suitable for a terminal, a redirect, or a checked-in documentation file. This guide uses the pod2text installed with Perl 5.38.2 on this machine. Allow about 10 minutes for a first conversion.
The route
Jump straight to the step you need, or tick off Done means at the end.
Before you start
You need a shell, Perl's pod2text command, and a readable input file containing POD. Check the command before working on a real document:
command -v pod2text
pod2text -h | sed -n '1,12p'
perl -v | sed -n '1,3p'
Expected output includes a path such as /usr/bin/pod2text, a usage synopsis, and Perl version 5.38.2 or another installed version. This is a read-only check. No elevated privileges are needed.
1. Convert a POD file to standard output
Give the input path as the first argument. With no output path, formatted text is written to standard output:
pod2text path/to/README.pod
A POD heading becomes a text heading and ordinary paragraphs are wrapped for the terminal. Markup such as C<code> is rendered for reading rather than printed as POD syntax. The normal right margin is column 76, and regular text is indented by four spaces.
Checkpoint
If the screen output is wider or narrower than expected, use an explicit width rather than relying on the terminal. A width is the column at which text wraps:
pod2text --width=72 path/to/README.pod
The short form is -w 72. Do not confuse this with the left margin: --margin moves all output, while --indent changes the indentation of regular text and =over blocks.
2. Save the result without changing the source
Supply an output path after the input path when you want a file:
pod2text path/to/README.pod /tmp/README.txt
sed -n '1,80p' /tmp/README.txt
Use a destination you control. The command writes the formatted result there; it does not edit the POD input. If the destination is an existing important file, stop and inspect the path first. A mistaken output path can replace that file, and the manpage does not promise a backup.
To keep the generated text in a project, write to a temporary name, inspect it, then replace the intended file only after the comparison is correct:
pod2text docs/guide.pod /tmp/guide.txt
diff -u docs/guide.txt /tmp/guide.txt
If the comparison is wrong, delete or ignore the temporary file and fix the POD. Your source remains the recovery copy.
3. Process a stream or several files
When the input argument is omitted, pod2text reads standard input. Use - explicitly when a script or pipeline makes the input source less obvious:
printf '%s\n' '=head1 Status' '' 'Generated from a stream.' | pod2text --width=60 -
The trailing - is the input name here, not a request for binary output. The result is text on standard output, so it can be piped into a pager or another read-only command.
Several input and output files can be supplied as pairs. This is useful when one process needs to render a small set of documents:
pod2text one.pod one.txt two.pod two.txt
Keep the pairs together. An extra or missing path can make the command interpret a filename as the wrong kind of argument.
4. Choose encoding deliberately
By default, output uses the input file's declared encoding, or UTF-8 when no encoding is declared on this non-EBCDIC system. For a known output contract, select an encoding explicitly:
pod2text --encoding=UTF-8 path/to/README.pod /tmp/README.txt
file -bi /tmp/README.txt
The --utf8 option is an equivalent compatibility spelling for UTF-8. Output encoding does not tell POD how to decode its input. If the source is not US-ASCII, declare its input encoding near the top of the POD with an =encoding command, normally before the main content. Otherwise Pod::Simple may guess and warn, especially for non-ASCII text.
If a character cannot be represented in the selected output encoding, the default error handling is die. You can choose --errors=stderr, --errors=pod, or --errors=none, but those modes trade a hard failure for a warning, an error section, or ignored errors. Use them only when that trade-off is part of your output policy.
5. Keep automation predictable
For scripts, check the exit status and capture standard error separately:
if pod2text --errors=die input.pod output.txt 2>output.err; then
test ! -s output.err
printf '%s\n' 'POD conversion passed'
else
status=$?
printf 'POD conversion failed (status %s)\n' "$status" >&2
sed -n '1,40p' output.err >&2
fi
With default error handling, a POD syntax error aborts with status 255. If a document produces no output, the command exits with status 1. A successful status does not mean every warning has vanished: for example, --errors=pod can include a POD ERRORS section while still returning 0 because output exists.
Leave the ANSI output, --overstrike, and --termcap options out of files intended for plain text. They add terminal presentation or control sequences. --termcap also depends on terminal information such as COLUMNS and TERMCAP, so its result can vary between sessions.
Done means
pod2text -hruns from the expected Perl installation.- The input file is unchanged and the output path is the one you inspected.
- Output width and encoding are explicit when another tool depends on them.
- Your script checks the exit status and keeps diagnostics separate from the rendered text.