ABCTEST_062506.DAT XYZTEST_062506.DAT ABCTEST_062406.DAT XYZTEST_062506.DAT ABCTEST_062406.DAT XYZTEST_062506.DAT ABCTEST_062406.DAT XYZTEST_062506.DAT #### sub scanDir() { $check ="ABCD" # this value will come from an array $base_dir = $_[0]; opendir(DIR, $base_dir) || die "Error: could not open input directory $base_dir"; @current_dir = readdir(DIR); chomp(@current_dir); foreach $current_dirs (@current_dir) { $file_name = $current_dirs; $var = substr($file_name, 0, 3); $newvar = substr($file_name,3); if($var eq $check){ $newFileName = $check . $newvar; } } closedir(DIR); }