#!/usr/bin/perl -w $num = 0; $count = 0; while (<>) { # Find x, y, z coordinates and store in separate arrays if ($_ =~ /^ATOM/) { @line = $_ =~ m/^(.....).(.....).(....).(...)..(....)....(........)(........)(........)/; $x = $line[5]; $arrayx[$num] = $x; $y = $line[6]; $arrayy[$num] = $y; $z = $line[7]; $arrayz[$num] = $z; ++$num; } # Count number of atoms if ($_ =~ /^ATOM/) { ++$count; } } # Calculate distance between all atom coordinates foreach $i (0..$count) { foreach $j ($i + 1..$count) { $dist = sqrt( ($arrayx[$i] - $arrayx[$j])**2 + ($arrayy[$i] - $arrayy[$j])**2 + ($arrayz[$i] - $arrayz[$j])**2 ); print "$dist\n"; } }