I see ysth beat me to this one, but here is the code I was working on anyway. It uses the opendir/readdir/loop method:
use File::Spec; # for portable filename operations
use File::Path; # to create the new subdirectory
use File::Copy; # to move the edited file
my $currentdir = '.';
my $newdir = File::Spec->catdir( $currentdir, 'newdir' );
# make the new subdirectory
mkpath( $newdir ) or die "error creating $newdir";
# get all filenames in the current directory
opendir( DIR, $currentdir ) or die "couldn't open $currentdir\n";
my @filenames = readdir DIR;
# get the program name so it's not moved if $currentdir eq '.'
my ( undef, undef, $progname ) = File::Spec->splitpath( $0 );
foreach my $file (@filenames)
# add the full path to the filename
my $pathfile = File::Spec->catfile( $currentdir, $file );
# skip if $file is a directory or this program
if( -d $pathfile or $file eq $progname )
# process file here
# move file to new subdir
my $newpath = File::Spec->catfile( $newdir, $file );
move( $pathfile, $newpath ) or print "error moving $file";
I'm sure more experienced Monks can come up with more elegant solutions, but this works on the tests I performed.
Update: Fixed code per parv's suggestion.