use File::Find; my $old_hostname= "D25573786-2k2"; my $new_hostname = "75219"; finddepth (\&update_file , "C:\/elmPaul" ); sub update_file_dir { if( /(.*)$old_hostname(.*)/i )# any files or directories { $orig = $File::Find::name ; $concat = $File::Find::dir . "\/$1$new_hostname$2"; rename($orig, $concat) || print "error can't rename $orig to $concat: $!"; } -f $_ && push (@files, "$File::Find::name"); } # end of sub update_file_dir foreach $file (@files ) { open (IN,"$file"); print "\nReading from file: $file \n"; @lines = ; close IN; foreach (@lines) { if ( /(.*?)$old_hostname(.*?)/i ) { s/(.*?)$old_hostname(.*?)/$1$new_hostname$2/sgi; } open (OUT,">$file"); print OUT @lines; } }