foreach my $file (@entries) { next if ($file =~ /^\.+$/); if ( -d $dir . '/' . $file) { runDir($prefix . $file . '_', $dir . '/' . $file); print "***up runDir($prefix . $file . '_', $dir . '/' . $file)\n"; } elsif ( ( -f $dir . '/' . $file ) && ( $file =~ /\.config$/ ) && ($file !~ /^$prefix/)) { my $suffix = $file; $suffix =~ s/^(\S+)-.+\.config$/$1.config/; print "****rename $dir . '/' . $file, $dir . '/' . $prefix . $suffix"."\n"; rename $dir . '/' . $file, $dir . '/' . $prefix . $suffix ; } } #### DCMS_DEMO_new_block2_checklist_tmp_rev2.html #### prefix output: ***up runDir(DCMS_DEMO_de_top_Block_DV_ . rev2 . '_', /home/sa/dcms_html_output/DCMS_DEMO/de_top/Block_DV . '/' . rev2) suffix output: Block_DV.config rename output: ****rename /home/sa/dcms_html_output/DCMS_DEMO/de_top/Block_DV . '/' . Block_DV.config, /home/sa/dcms_html_output/DCMS_DEMO/de_top/Block_DV . '/' . DCMS_DEMO_de_top_Block_DV_ . Block_DV.config