#! perl -slw use strict; printf "%s", scalar ; my @points = map[ split ' ', $_ ], ; my $i=0; while ($i < @points-2) #quit when there aren't 2 points left { my ($x1,$y1) = @{$points[$i]}; my ($x2,$y2) = @{$points[$i+1]}; if ( ($y2 - $y1 ) / ( $x2 - $x1 ) < 0 ) { splice @points,$i,2; #remove both points $i--; #backup a point to restart $i=0 if $i<0; #boundary condition at index 0 } else { $i++; } } print join ' ', @$_ for @points;