This is commonly known as the 'Schwartzian Transform', as it was first discussed in detail by Randal Schwartz in a column of Unix Review。List file name sorted by the file contains how many lines of 'perl'.
my @pairs =map{[ $_, count_perls($_)]} @filenames;
my @sorted_pairs = sort { $a->[1]<=> $b->[1]} @pairs;
my @sorted =map{ $_->[0]} @sorted_pairs;
sub count_perls {
local $_; # Avoid clobbering caller's $_
my ($filename) = @_;
my $count = 0;
open(FH, "<", $filename) or die "Cannot open $filename - $!\n";