tie @log, 'Tie::File', $logfile or displayError("could not open logfile"); while ($some_condition) { #do some other stuff, and unshift @log, $info_to_be_logged; } # find out how long the logfile is, and truncate it $length = @log; $truncate = $length - 150; if ($truncate > 0) { $#log -= $truncate; } untie @log;