Q:

Cleanup Perl code: my $export = $doc; $export =~ s:\.odt:\.pdf:;

Perl code fragment:
my $export = $doc;
$export =~ s:\.odt:\.pdf:;

How would this be written cleaner? Not simply what are 900 other ways to write it, TMTOWTDI.

A:

 
my ($export = $doc) =~ s{\.odt}{\.pdf};

UPDATE: That solution doesn't compile (note to self: test before posting on SO). Instead you could say
(my $export = $doc) =~ s{\.odt}{\.pdf};

A:

I go for [.] to match a literal period:
$export ~= s{[.]odt$}{.pdf};

Note that only the first half of the s/// call is a regular expression.  The replacement is a normal string, and does not require a period to be escaped.
You might want to represent files as objects and not strings, though, with Path::Class.

