#!/usr/bin/perl -w use strict; my $file = "somefile"; open (FILE, '<', $file) or die "unable to open $file\n"; my $first_line = ; my $last_line; while(){$last_line = $_;} print "$first_line"; #do what you need with them here print "$last_line";