in reply to find biggest file and use awk

Your subject says that you want to use awk, which your code already does, and it works for me. You haven't indicated what the problem is?

Although you could just use the code you have, I'm guessing your question is how to do this in Perl.

Piece 1: List files with glob (there are other ways, such as readdir or Path::Tiny, but glob is good for simple tasks), e.g. glob('/tmp/dir1/d1*')

Piece 2: Get the size of a file with -s, e.g. -s $filename

Piece 3: Using an array of arrays to hold the filenames and sizes (see also perlreftut)

Piece 4: Sort numerically with sort, e.g. sort {$b<=>$a} @filesizes

Putting it all together:

my @filenames = glob '/tmp/dir1/d1*'; my @files_and_sizes; for my $filename (@filenames) { my $filesize = -s $filename; push @files_and_sizes, [$filename, $filesize]; } use Data::Dumper; # just for demo & debugging print Dumper \@files_and_sizes; # just for demo & debugging @files_and_sizes = sort { $$b[1] <=> $$a[1] } @files_and_sizes; print Dumper \@files_and_sizes; # just for demo & debugging my $var1 = $files_and_sizes[0][0]; print $var1;

This could even be dramatically shortened into a one-liner, esp. if you replace the for with map. There are also several other ways to do this, e.g. with modules.