#!/usr/bin/perl -w use strict; use File::Find; my $root_dir = '/temp'; my $new_shebang = '#!/usr/bin/local/perl'; find ( \&fix_shebang, $root_dir ); sub fix_shebang { return unless /\.(?:pl|cgi)/; local $/; open F, "+<$_" or die "Can't open $_: $!\n"; my $file = ; if ($file =~ s/^#!.*perl(.*)\n/$new_shebang$1\n/) { seek F, 0, 0; truncate F, 0; print F $file; print "Found and modified: $File::Find::name\n"; } else { print "Found (no modify): $File::Find::name\n"; } close F; }