use strict; use warnings; while(){ if(eof){ #Check if the last line has ' last ' print ~/\slast\s/ ? 'yes' : 'no'; } } __DATA__ one line two lines three lines this is the last one