http://qs321.pair.com?node_id=932617


in reply to Need to search for a string in a file

You needn't pull the whole file into memory just to search for one line.
The caret character,(^), means start of the line in a regex. Read perlre, these meta-characters is the second subject covered.
You can match save and exit the loop in one statement.
sub get_file_from_log(){ my $log_name=shift; open(my $log_file, "<", $log_name); my $file_name; while (<logFile>){ last if ($file_name) = /^Generated filename\s*=\s*(.+)$/; } return $file_name; }

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."