# from the venerable cookbook, recipe 8.4 @lines = reverse ; foreach $line (@lines) { # do something with $line # until blank line, which happens to be # the first blank line from top }