#! /usr/bin/perl use strict; use warnings; use 5.010; use Data::Dumper; my @array = ( [ 3, 7 ], [ 1, 2 ], [ 2, 4 ], ); # Schwartzian Transform; read it from the end my @sorted = # restore original data map { $_->[0] } # sort numerically by the calculated differemce sort { $a->[1] <=> $b->[1] } # create temp array ref; first element is the original data # second element is the square of the difference between second and first value of original dataset map { [ $_, ($_->[1] - $_->[0])**2 ] } # parse list of array duples @array; say Dumper \@sorted;