#!/usr/bin/env perl use strict; use warnings; use List::Util 'sum'; my $allowable_drift = 0.5; my @test_data; while () { my $test_field = (split)[3]; if (@test_data < 3) { print; push @test_data, $test_field; next; } my $avg = sum(@test_data) / 3; if (abs($avg - $test_field) <= $allowable_drift) { print; shift @test_data; push @test_data, $test_field; } else { print "Outlier: $_"; } } __DATA__ A15 26.62 765 27.30 4.3 A11 26.63 763 27.28 4.2 A12 26.68 767 27.29 4.3 A16 26.64 768 27.30 4.2 A11 26.62 761 27.31 4.1 A15 26.62 765 27.30 4.3 A15 26.63 763 27.28 4.2 A16 26.68 767 2.29 4.3 A17 26.64 768 27.30 4.2 A18 26.62 761 27.31 4.1 #### A15 26.62 765 27.30 4.3 A11 26.63 763 27.28 4.2 A12 26.68 767 27.29 4.3 A16 26.64 768 27.30 4.2 A11 26.62 761 27.31 4.1 A15 26.62 765 27.30 4.3 A15 26.63 763 27.28 4.2 Outlier: A16 26.68 767 2.29 4.3 A17 26.64 768 27.30 4.2 A18 26.62 761 27.31 4.1 #### __DATA__ A15 26.62 765 27.30 4.3 A16 26.68 767 2.29 4.3 A11 26.63 763 27.28 4.2 A12 26.68 767 27.29 4.3 A16 26.64 768 27.30 4.2 A11 26.62 761 27.31 4.1 A15 26.62 765 27.30 4.3 A15 26.63 763 27.28 4.2 A17 26.64 768 27.30 4.2 A18 26.62 761 27.31 4.1 #### A15 26.62 765 27.30 4.3 A16 26.68 767 2.29 4.3 A11 26.63 763 27.28 4.2 Outlier: A12 26.68 767 27.29 4.3 Outlier: A16 26.64 768 27.30 4.2 Outlier: A11 26.62 761 27.31 4.1 Outlier: A15 26.62 765 27.30 4.3 Outlier: A15 26.63 763 27.28 4.2 Outlier: A17 26.64 768 27.30 4.2 Outlier: A18 26.62 761 27.31 4.1