--- bin/aclocal.in
+++ bin/aclocal.in
@@ -21,7 +21,8 @@
 
 BEGIN
 {
-  unshift (@INC, '@datadir@/@PACKAGE@-@APIVERSION@')
+  my $pkgdatadir = $ENV{"AUTOMAKE_PERLLIBDIR"} || '@datadir@/@PACKAGE@-@APIVERSION@';
+  unshift (@INC, $pkgdatadir)
     unless $ENV{AUTOMAKE_UNINSTALLED};
 }
 
--- bin/automake.in
+++ bin/automake.in
@@ -26,7 +26,8 @@
 
 BEGIN
 {
-  unshift (@INC, '@datadir@/@PACKAGE@-@APIVERSION@')
+  my $pkgdatadir = $ENV{"AUTOMAKE_PERLLIBDIR"} || '@datadir@/@PACKAGE@-@APIVERSION@';
+  unshift (@INC, $pkgdatadir)
     unless $ENV{AUTOMAKE_UNINSTALLED};
 
   # Override SHELL.  This is required on DJGPP so that system() uses
$
