use strict; my $SCFDoneLowSoFar = 0.0; # The lowest energy found so far my $FileLowSoFar = ''; # The file containing the lowest energy so far foreach my $files (<*log>){ # Loop over all of the files my $E=`grep "SCF Done" $files|awk "{print \\\$5}"`; chomp($E);# Find the energy in this file # Check if the energy in this file is LOWER than the lowest energy so far # If it is, then it is the NEW lowest energy so far # and the file containing is the new FileLowSoFar print "File $files has energy $E and the lowest energy so far is $SCFDoneLowSoFar\n"; } print "The lowest total energy was $ELowSoFar\n"; print "This was in file $FileLowSoFar\n";