Here's an attempt (without select) lst = {1, 2, 2, 1, 2, 5, 2, 4}; n = 4; p = 1; Flatten[If[Abs[Take[#, -1] - Mean[Drop[#, -1]]][[1]] > p *StandardDeviation[Drop[#, -1]], Take[#, -1], {}] & /@ Partition[lst, n + 1, 1, 1]] // First Alternatively with Select. Flatten@Select[Partition[lst, n + 1, 1, 1], Abs[Take[#, -1] - Mean[Drop[#, -1]]][[1]] > p*StandardDeviation[Drop[#, -1]] &] // Last