diff --git a/contrib/windows-icons.pl b/contrib/windows-icons.pl
index cb2de0313..fc93af083 100755
--- a/contrib/windows-icons.pl
+++ b/contrib/windows-icons.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2012 Red Hat Inc.
#
@@ -24,6 +24,7 @@
# ./run ./contrib/windows-icons.pl /path/to/windows-disk.img
use strict;
+use warnings;
use Sys::Guestfs;
use File::Temp qw{tempdir};
diff --git a/examples/guestfs-performance.pod b/examples/guestfs-performance.pod
index 7cf10aaa2..caa7535a9 100644
--- a/examples/guestfs-performance.pod
+++ b/examples/guestfs-performance.pod
@@ -322,10 +322,11 @@ L
L
- #!/usr/bin/perl -w
+ #!/usr/bin/env perl
use strict;
use threads;
+ use warnings;
use Sys::Guestfs;
use Time::HiRes qw(time);
diff --git a/generator/bindtests.ml b/generator/bindtests.ml
index 5358ff17c..095970452 100644
--- a/generator/bindtests.ml
+++ b/generator/bindtests.ml
@@ -370,11 +370,12 @@ let () =
pr "print_endline \"EOF\"\n"
and generate_perl_bindtests () =
- pr "#!/usr/bin/perl -w\n";
+ pr "#!/usr/bin/env perl\n";
generate_header HashStyle GPLv2plus;
pr "\
use strict;
+use warnings;
use Sys::Guestfs;
diff --git a/perl/examples/create_disk.pl b/perl/examples/create_disk.pl
index 0b9fa8db7..3b406833a 100755
--- a/perl/examples/create_disk.pl
+++ b/perl/examples/create_disk.pl
@@ -1,8 +1,9 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# Example showing how to create a disk image.
use strict;
+use warnings;
use Sys::Guestfs;
my $output = "disk.img";
diff --git a/perl/examples/inspect_vm.pl b/perl/examples/inspect_vm.pl
index 6d95b6978..04fbae6d9 100755
--- a/perl/examples/inspect_vm.pl
+++ b/perl/examples/inspect_vm.pl
@@ -1,8 +1,9 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# Example showing how to inspect a virtual machine disk.
use strict;
+use warnings;
use Sys::Guestfs;
if (@ARGV < 1) {
diff --git a/pick-guests.pl.in b/pick-guests.pl.in
index bfc97d8f4..1ccc04b9c 100755
--- a/pick-guests.pl.in
+++ b/pick-guests.pl.in
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# @configure_input@
# Copyright (C) 2009-2015 Red Hat Inc.
#
@@ -20,6 +20,7 @@
# This is used by 'make check-valgrind-local-guests'.
use strict;
+use warnings;
use Sys::Guestfs;
use Sys::Virt;
diff --git a/podwrapper.pl.in b/podwrapper.pl.in
index b354db653..3810f7214 100755
--- a/podwrapper.pl.in
+++ b/podwrapper.pl.in
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# podwrapper.pl
# Copyright (C) 2010-2015 Red Hat Inc.
# @configure_input@
diff --git a/rescue/test-virt-rescue.pl b/rescue/test-virt-rescue.pl
index 9547fd698..22538824a 100755
--- a/rescue/test-virt-rescue.pl
+++ b/rescue/test-virt-rescue.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2012-2015 Red Hat Inc.
#
@@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
+use warnings;
my $progname = $0;
$progname =~ s{.*/}{};
diff --git a/resize/test-virt-resize.pl b/resize/test-virt-resize.pl
index be9c9b4cd..1923398c0 100755
--- a/resize/test-virt-resize.pl
+++ b/resize/test-virt-resize.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# Copyright (C) 2010-2015 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/bigdirs/test-big-dirs.pl b/tests/bigdirs/test-big-dirs.pl
index 47f076023..40038b781 100755
--- a/tests/bigdirs/test-big-dirs.pl
+++ b/tests/bigdirs/test-big-dirs.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/btrfs/test-btrfs-misc.pl b/tests/btrfs/test-btrfs-misc.pl
index 0a8e942ba..cfa9cbbc3 100755
--- a/tests/btrfs/test-btrfs-misc.pl
+++ b/tests/btrfs/test-btrfs-misc.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2013 Red Hat Inc.
#
diff --git a/tests/btrfs/test-btrfs-subvolume-default.pl b/tests/btrfs/test-btrfs-subvolume-default.pl
index fd20fa2dc..c3d62d307 100755
--- a/tests/btrfs/test-btrfs-subvolume-default.pl
+++ b/tests/btrfs/test-btrfs-subvolume-default.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2012 Red Hat Inc.
#
diff --git a/tests/daemon/test-btrfs.pl b/tests/daemon/test-btrfs.pl
index 7a0c345d7..302ecb97b 100755
--- a/tests/daemon/test-btrfs.pl
+++ b/tests/daemon/test-btrfs.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2015 Red Hat Inc.
#
diff --git a/tests/daemon/test-daemon-start.pl b/tests/daemon/test-daemon-start.pl
index 91e008aa4..8cc59d9e1 100755
--- a/tests/daemon/test-daemon-start.pl
+++ b/tests/daemon/test-daemon-start.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2015 Red Hat Inc.
#
diff --git a/tests/discard/test-blkdiscard.pl b/tests/discard/test-blkdiscard.pl
index e080350d7..9f136ecd9 100755
--- a/tests/discard/test-blkdiscard.pl
+++ b/tests/discard/test-blkdiscard.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2014 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/discard/test-discard.pl b/tests/discard/test-discard.pl
index dbcf6a5b3..0253a9d0b 100755
--- a/tests/discard/test-discard.pl
+++ b/tests/discard/test-discard.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2014 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/discard/test-fstrim.pl b/tests/discard/test-fstrim.pl
index cbd28bfb2..88feb06d7 100755
--- a/tests/discard/test-fstrim.pl
+++ b/tests/discard/test-fstrim.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2014 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/disk-labels/test-disk-labels.pl b/tests/disk-labels/test-disk-labels.pl
index a74e30013..17db5e18b 100755
--- a/tests/disk-labels/test-disk-labels.pl
+++ b/tests/disk-labels/test-disk-labels.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/disks/test-max-disks.pl b/tests/disks/test-max-disks.pl
index 9561b6b9b..11d465189 100755
--- a/tests/disks/test-max-disks.pl
+++ b/tests/disks/test-max-disks.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/events/test-console-debug.pl b/tests/events/test-console-debug.pl
index eb6a774b7..777a05901 100755
--- a/tests/events/test-console-debug.pl
+++ b/tests/events/test-console-debug.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/fuzz/fuzz-inspection.pl b/tests/fuzz/fuzz-inspection.pl
index 9fcd98ee8..805558da6 100755
--- a/tests/fuzz/fuzz-inspection.pl
+++ b/tests/fuzz/fuzz-inspection.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# Fuzz-test libguestfs inspection.
# Copyright (C) 2013 Red Hat Inc.
#
diff --git a/tests/guests/guest-aux/make-fedora-img.pl b/tests/guests/guest-aux/make-fedora-img.pl
index eae11d61e..bd986057a 100755
--- a/tests/guests/guest-aux/make-fedora-img.pl
+++ b/tests/guests/guest-aux/make-fedora-img.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2010-2015 Red Hat Inc.
#
diff --git a/tests/guests/guest-aux/make-guests-all-good.pl b/tests/guests/guest-aux/make-guests-all-good.pl
index aafcc8e67..ab6451a6e 100755
--- a/tests/guests/guest-aux/make-guests-all-good.pl
+++ b/tests/guests/guest-aux/make-guests-all-good.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2013 Red Hat Inc.
#
diff --git a/tests/hotplug/test-hot-add.pl b/tests/hotplug/test-hot-add.pl
index 034cff440..18ff7c47f 100755
--- a/tests/hotplug/test-hot-add.pl
+++ b/tests/hotplug/test-hot-add.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/hotplug/test-hot-remove.pl b/tests/hotplug/test-hot-remove.pl
index 087399d41..3e7cf72ed 100755
--- a/tests/hotplug/test-hot-remove.pl
+++ b/tests/hotplug/test-hot-remove.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/hotplug/test-hotplug-repeated.pl b/tests/hotplug/test-hotplug-repeated.pl
index 306bcebc1..142f44521 100755
--- a/tests/hotplug/test-hotplug-repeated.pl
+++ b/tests/hotplug/test-hotplug-repeated.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/journal/test-journal.pl b/tests/journal/test-journal.pl
index 38950f989..6d8675b13 100755
--- a/tests/journal/test-journal.pl
+++ b/tests/journal/test-journal.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2013 Red Hat Inc.
#
diff --git a/tests/lvm/test-lvm-mapping.pl b/tests/lvm/test-lvm-mapping.pl
index 83533336d..748d0e2c6 100755
--- a/tests/lvm/test-lvm-mapping.pl
+++ b/tests/lvm/test-lvm-mapping.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2010 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/nbd/test-nbd.pl b/tests/nbd/test-nbd.pl
index 6353b25b9..0ad299ca0 100755
--- a/tests/nbd/test-nbd.pl
+++ b/tests/nbd/test-nbd.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/protocol/test-launch-race.pl b/tests/protocol/test-launch-race.pl
index f933bfeb5..fadfdbf6c 100755
--- a/tests/protocol/test-launch-race.pl
+++ b/tests/protocol/test-launch-race.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2010 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/regressions/test-noexec-stack.pl b/tests/regressions/test-noexec-stack.pl
index 68bbb0b7e..a2741b976 100755
--- a/tests/regressions/test-noexec-stack.pl
+++ b/tests/regressions/test-noexec-stack.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2009 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/selinux/run-test.pl b/tests/selinux/run-test.pl
index 89846aef9..f0f241f66 100755
--- a/tests/selinux/run-test.pl
+++ b/tests/selinux/run-test.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/syslinux/test-syslinux.pl b/tests/syslinux/test-syslinux.pl
index cea0e5426..54d23c181 100755
--- a/tests/syslinux/test-syslinux.pl
+++ b/tests/syslinux/test-syslinux.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/tmpdirs/test-tmpdirs.pl b/tests/tmpdirs/test-tmpdirs.pl
index a9acd8eb4..90aa31e91 100755
--- a/tests/tmpdirs/test-tmpdirs.pl
+++ b/tests/tmpdirs/test-tmpdirs.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
diff --git a/tests/xfs/test-xfs-misc.pl b/tests/xfs/test-xfs-misc.pl
index 1d0947480..f60d6f772 100755
--- a/tests/xfs/test-xfs-misc.pl
+++ b/tests/xfs/test-xfs-misc.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# libguestfs
# Copyright (C) 2013 Red Hat Inc.
#
diff --git a/tests/xml/rhbz701814.pl b/tests/xml/rhbz701814.pl
index 01fa128ec..aad898fd9 100755
--- a/tests/xml/rhbz701814.pl
+++ b/tests/xml/rhbz701814.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# Copyright (C) 2012 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
@@ -19,6 +19,7 @@
# https://bugzilla.redhat.com/show_bug.cgi?id=701814
use strict;
+use warnings;
use Sys::Guestfs;
diff --git a/tools/virt-list-filesystems b/tools/virt-list-filesystems
index 62e862bd6..a4d92ff74 100755
--- a/tools/virt-list-filesystems
+++ b/tools/virt-list-filesystems
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# virt-list-filesystems
# Copyright (C) 2009-2015 Red Hat Inc.
#
diff --git a/tools/virt-list-partitions b/tools/virt-list-partitions
index 5579840c9..b9cbfdd7c 100755
--- a/tools/virt-list-partitions
+++ b/tools/virt-list-partitions
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# virt-list-partitions
# Copyright (C) 2010 Red Hat Inc.
#
diff --git a/tools/virt-tar b/tools/virt-tar
index a4d88a486..7ac9d95d3 100755
--- a/tools/virt-tar
+++ b/tools/virt-tar
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# virt-tar
# Copyright (C) 2009-2015 Red Hat Inc.
#
diff --git a/tools/virt-win-reg b/tools/virt-win-reg
index f4277e895..57188c81b 100755
--- a/tools/virt-win-reg
+++ b/tools/virt-win-reg
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# virt-win-reg
# Copyright (C) 2010 Red Hat Inc.
#