It is true that your script will replace the Perl path within the shebang
string, but it will also replace it if the same string is
anywhere inside the script.
perl -pi.bak -e 's[^#!/usr/local/bin/perl][#!/usr/bin/perl]' *.pl
This one should guarantee that the replacement happens only at the beginning
of a string. To ensure that the replacement is carried out only
once in each script, though, one more check is needed.
perl -pi.bak -e 'BEGIN{$c=@ARGV};s[^#!/usr/local/bin/perl][#!/usr/bin/
+perl] && $c-- if $c> @ARGV' *.pl
which translates roughly into
#!/usr/bin/perl -w -i.bak
use strict
our $count=@ARGV;
while (<>) {
if ($count > @ARGV) {
s[^#!/usr/local/bin/perl][#!/usr/bin/perl];
$count--;
}
print;
}