#!/usr/bin/env perl use strict; use warnings; my @circles = ( { x => 3.0, y => 10.0, r => 5.0 }, { x => 4.0, y => 9.0, r => 2.0 }, { x => 12.0, y => 4.0, r => 4.0 }, ); while (my $one = shift @circles) { for my $other (@circles) { my $dx2 = ($one->{x} - $other->{x}) ** 2; my $dy2 = ($one->{y} - $other->{y}) ** 2; my $r2 = ($one->{r} + $other->{r}) ** 2; if ($dx2 + $dy2 < $r2) { warn "Potential overlap: $one->{x}, $one->{y}, $one->{r} with $other->{x}, $other->{y}, $other->{r}\n"; } } }