perl -ne 'if ($.<6) {print} else {shift @arr}; push @arr,$_; END {print @arr}' file