if (@files) { foreach my $file (@files) { if ($file = glob(($base)."*.txt")){ move($file, $to) or die ("The move operation failed for ".$file." because ".$!); print "Moved ".$file." to ".$to or die $!; } next; } } else { print "No files found to move\n"; }