in reply to Capturing the first and last line of a file ?

A slightly modification of your code will avoid memory-problems with big files an rise performance. It's not necessary to put the whole file into an array.
#!/usr/bin/perl use warnings; use strict; open (FOO, "test") || die "ERROR Unable to open test: $!\n"; my $last; my $first = <FOO>; while (<FOO>) { $last = $_ } close FOO; print "\$first: $first"; print "\$last: $last";
But in this case i would prefer head and tail if available
head -1 test;tail -1 test