my @lines; my $currLine = 0; my $maxLines = 10; # Go through the file, saving the last $maxLines while (<>){ $lines[$currLine] = $_; $currLine++; $currLine = 0 if ($currLine == $maxLines); } # Print out the last $maxLines for (1..$maxLines){ print $lines[$currLine]; $currLine++; $currLine = 0 if ($currLine == $maxLines); }