#!/bin/perl -w; use strict; foreach my $file (glob( "files/*")) # put the files dir here { rename( $file, correct( $file)) or die "could not rename $file into " . correct( $file) . ": $!"; } sub correct { my $date= shift; my ($month, $year)= $date=~ /^(\d\d)(\d\d)/; if( $year > 50) { $year +=1900} else { $year+=2000}; return $year.$month; } #### my @sorted_filenames= map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, correct($_)] } glob( "files/*");