in reply to Creating Filenames using variables

# original file name :
$mon = "MON.DOC";

# split name into it's 3 letter day name and the extension
# each part will go in $1 & $2 by default :
$mon =~ /^(\w{3})(\.DOC)/;

# save parts in appropiately named variables :
($day, $ext) = ($1, $2);

# the following code will run the 'date' command and print the output to STDOUT
# however, the return value of the sub 'system' is the exit value of the 'date'
# command execution, which is usually 0 for success, therefore $date would be
# equal to 0 (zero) :
# $date = system ("date \'+%m%d%Y\'");

# what you want to do instead is run the 'date' command with backticks instead
# of 'system'.
# this way, the output of 'date' is not printed to STDOUT, but rather returned
# and stored into $date.
# chomp is necessary to remove the newline character :
chomp($date = `date '+%m%d%Y'`);

# To get the current date. If I want $mon to change to MON_02082001.DOC, what do i do next???

$mon = $day . '_' . $date . $ext;
print $mon;

# the output should be as follows :
# MON_02082001.DOC