in reply to get file name to create folder

This will work on the current folder:
#!/usr/bin/perl use warnings; use strict; use File::Copy; while (my $filename=<*.txt>) { next if !($filename =~ m/_(\d{6})\.txt\z/); my $date=$1; if (!-e $date) { mkdir $date; } else { if (!-d $date) { die "$date already exists and is not a folder"; } elsif (!-x $date) { die "Wrong permissions on preexisting folder $date"; } } move($filename,"$date/") or die "Couldn't move $filename to $date: $!"; }
If you want to remove the _yymmdd from the file name while moving, replace the last line with
my $newname = $filename; $newname =~ s/_\d{6}//; move($filename,"$date/$newname") or die "Couldn't move $filename to $date/$newname: $!";

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan