in reply to Array reference

If I understand your requirements correctly the following sample should do it for you:

#!/usr/bin/perl use strict; use warnings; my $inData = <<IN; ID1 ch1 70 mir abc xyz ch2 2050 ID2 ch1 90 mir abc xyz ch2 4000 ID3 ch1 100 mir abc xyz ch2 2045 ID4 ch1 120 mir abc xyz ch2 2025 IN open my $inFile, '<', \$inData; my @lines = sort {$a->[1] <=> $b->[1]} map {/(\d+)$/; [$_, $1]} <$inFi +le>; pop @lines if $lines[-1][1] - $lines[0][1] >= 500; print for sort map {$_->[0]} @lines;

Prints:

ID1 ch1 70 mir abc xyz ch2 2050 ID3 ch1 100 mir abc xyz ch2 2045 ID4 ch1 120 mir abc xyz ch2 2025

The trick is to pair the line text with the sort key (done in the map) then subsequently use the key or the original line as required.

True laziness is hard work