use Text::Diff;
for($count = 0; $count <= 1000; $count++){
my $data_dir=\"archive/oswiostat/oracleapps.*dat\";
my $data_file= `ls -t $data_dir | head -1`;
Note that I'm answering your original question, why the stat() seemed to fail, rather than the newly edited question title, which asks something different.
This is the fix:
my $data_file= `ls -t $data_dir | head -1`;
chomp($data_file);
The reason this is the fix is a little murky. Without that chomp(), $data_file contains a trailing newline: "some_filename\n". The two argument form of open() ignores trailing newlines in filenames and I don't know why because two-arg open mimics shell behavior. Your call to stat(), however, does not ignore the newline in the filename, so it is stat()ing a non-existent file and thus $stats1 is undef.