in reply to upto match please, my one-lina!!
So it can run also under use strict:
perl -Mstrict \ -ne'/regex(?{print @@; exit})/;' \ -e'shift(@@) if push(@@,$_)>5' file
In Section
Seekers of Perl Wisdom