use strict; # duh. use File::Find; find ( sub { open IN, "< $_" || return; # silently discard failed open chomp(my $firstline = ); # read in first line and $firstline =~ /^#!.*perl[\s\Z]/ && do { # check for a shebang $firstline = "#!$^X$'"; # replace with your own shebang chomp(my @nextlines = ); open OUT, "> $_" && do { # print the file back out map {print OUT $_,$/;} $firstline, @nextlines; close OUT; } # the next bit is a little more concise, but won't replace newlines #$firstline = "#!$^X$'$/"; #my @nextlines = ; #open OUT, "> $_" && do { # map {print OUT} $firstline, @nextlines; # close OUT; #} close IN; }, qw| /source/code/directory /another/source/dir |; )