in reply to Call for code samples!

To print the first and last line of each file:
$/ = undef; while (<>) { print "\n$ARGV\n", / (.+?) ^.*^ (.+?) \z/xms }
To find the first and last match for a pattern:
(In this case, 'DT=20011105.112009'-style time-stamps in a log file)
$dtrx = qr/[Dd][Tt]=(\d{8}\.\d{6})/; $/ = undef; while (<>) { ($aa, $z) = /$dtrx # get the first one (?: # and maybe, .* # after maybe many lines, ^.*? $dtrx # the first one on the last line )? # that has one /mxs; $aa or next; $z ||= ''; # or '' if no more print "$ARGV\t $aa -- $z\n"; }
In this case there can be more than one such pattern on a line and it's the first one that is valid.

The point being that the /s makes a greedy, black-hearted .* for going straight to the end of the (presumedly long) file, ignoring linebreaks.   Then the /m (together with the ? to reign in dot-star) allows backtracking by line to find the first match on a line with matches.  

update:   These started out (obviously) as one liners, then got thrown into files.  The first time I actually looked at them was when I grabbed them to throw up here which, of course, lead to exploring MTOWTDI.  The first seems clearest this way. The second started out being far more complicated which is why it's in multi-line /x format.

  p