in reply to print matching lines

while(<DATA>){$q[($.-1)%4]=$_;print $q[0] if (($.-1)%4==3)&&(m/ord/s)} __DATA__ # input 1 xxx yyyy ord # input 2 xxx yyy 1 # input 3 xxx yyy ord

--
By a scallop's forelocks!