#!/usr/bin/env perl -l use strict; use warnings; # Set these constant values my %month_num_for = qw{ January 1 February 2 March 3 April 4 May 5 June 6 July 7 August 8 September 9 October 10 November 11 December 12 }; my $format = '%4d%02d%02d-%s'; # Get this data from file my $old_filename = 'abc001'; my $long_date = 'January 5, 2002'; # Split up the long format date my ($month, $day, $year) = split /\,?\s+/, $long_date; # Generate the new filename my $new_filename = sprintf $format, $year, $month_num_for{$month}, $day, $old_filename; # For testing print "New filename: $new_filename"; # When you're happy with the testing # rename $old_filename => $new_filename