I actually prefer using MakeMaker (and h2xs) to perform this kind of task. MM allows you to specify perl programs to run at compile time as arguments to the WriteMakefile() routine:
WriteMakefile(
NAME => 'Test::Bin',
VERSION_FROM => 'lib/Test/Bin.pm', # finds $VERSION
PREREQ_PM => {}, # e.g., Module::Name => 1.1
PL_FILES =>
{ 'bin/test.PL $(INSTALLSITELIB) $(INSTALLSITEARCH)'
=> 'lib/Test/Bin.pm' },
);
The PL_FILES attribute allows you to specify the .PL files and which files they should modify. I add the $(INSTALLSITELIB) $(INSTALLSITEARCH) as arguments so the perl program will receive those macros from the makefile. Then, for example, I would transform a package like the following:
package Test::Bin;
use 5.008002;
use strict;
use warnings;
use '###LIBPREFIX###'; # Use some easily matchable phrases
use '###ARCPREFIX###';
1;
__END__
by using this .PL file:
#!/usr/bin/perl -w -pi~
# Use command line options to read and write file(s).
use strict;
our ($lib, $arc);
BEGIN {
$lib = shift @ARGV; # Shift off the arguments so they are
$arc = shift @ARGV; # not processed as files
}
s/\Q###LIBPREFIX###\E/$lib/; # perform substitutions
s/\Q###ARCPREFIX###\E/$arc/;
1;
__END__
The end result is at least similar to what you are looking for:
package Test::Bin;
use 5.008002;
use strict;
use warnings;
use '/home/orderthruchaos/local/lib/perl5/site_perl/5.8.2';
use '/home/orderthruchaos/local/lib/perl5/site_perl/5.8.2/i686-linux';
require Exporter;
our $VERSION = '0.01';
1;
__END__
Hope this helps.