When you say user gives a max limit (in percentage), is that for all the files in the directory or only the target files in the directory? e.g. say you are supposed to just check 25% (size, not quantity) and 75% of the directory is made up of extensions you are not interested in, does that mean you will scan all of the files with extensions you are interested in?
I can give you one approach (assuming the max limit given by user is for % of files that match extension (not % of all files):
Use File::Find to find all files with extensions you are interested in.
With the help of "-s" or stat() to get the file sizes, build a data structure that looks like this:
$myFiles = {
"dir1" => { filelist => [ { filename => "file1.txt", size => 123 },
{ filename => "file2.doc", size => 456 },
+],
dir_size => 579, },
...
};
Iterate through each directory in this structure.
For each random file in "filelist" (can use Shuffle in List::Util for this), scan/process file as long as sum of size of files processed in the directory does not exceed the user supplied percentage of dir_size.