Return Full File Path To Array PERL

Iam trying to load the full path of multiplie files in the same directory to an array if the filenames matches a pattern. The following is the current code;

where $input=C:\test

# change to and open the comparison directory
chdir("$input2") || die "Cannot change dir: $!";
opendir(DIR2, "$input2") || die "Cannont open dir: $!";
# read flie names to an array with user specified path
foreach $file2 (readdir DIR2)
{
 if($file2 =~ /lds/)
  {
   @files2 = join("\\", $input2,$file2);
  }
}
close(DIR2);

The above code is only returning the last file in the directory with the full path.

Any suggestions on how to accomplish this?

That's because you're reassigning @files2 every time, overwriting the old contents. You'll have to push new stuff onto it if you want to keep everything.

Thanks for the explinaiton Pluid. I figured that out about 10mins after posting this.

Yet, I found a more efficient way of returning the full path of the files to an array

 
$input1 = "C:\test";
@files1 = grep{/lds/} <$input1*>;

This way I do not have to change directories.