in reply to AWTDI: Renaming files using regexp

You can achieve this with a global substitution using regular expression look ahead. Like this

use strict; use warnings; while(<DATA>) { chomp; my $old = $_; s/\.(?=.*?\.)/_/g; print "Change: $old to $_\n"; } __END__ test0.file0.new_20060411.zip test1.file1.new_20060411.zip test2.file2.new_20060411.zip test3.file3.new_20060411.zip

produces

Change: test0.file0.new_20060411.zip to test0_file0_new_20060411.zip Change: test1.file1.new_20060411.zip to test1_file1_new_20060411.zip Change: test2.file2.new_20060411.zip to test2_file2_new_20060411.zip Change: test3.file3.new_20060411.zip to test3_file3_new_20060411.zip

The substitution globally replaces every dot with an underscore as long as that dot is followed somewhere later in the line by another dot. Thus, it will not replace the dot that precedes the extension as it is the last one.

I hope this helps.

Cheers,

JohnGG