#! perl -slw use strict; $/=''; while( my @lines = split "\n", ) { my( @left, @right, @Ldist, @Rdist ); ## The only way I know to ensure $1 & $2 are cleared! for( @lines ) { 'a' =~ m[.]; push @left, $1 if m[ \x5b \s+ ( [A-Z0-9]+ ) \s+ \x5d -+ ( [\d\.]+ . )? ]x; $Ldist[ $#left ] = $2||'-' if $1; ## The only way I know to ensure $1 & $2 are cleared! 'a' =~ m[.]; push @right, $2 if m[ - ( [\d\.]+ . )? -+ \x5b \s+ ( [A-Z0-9]+ ) \s+ \x5d ]x; $Rdist[ $#right ] = $1||'-' if $2; } print "@left (@Ldist) connect to @right (@Rdist)"; } __DATA__ [ ABC12 ]----------38.00M----------[ DEF23 ] |---16M------[ DEF23 ] [ ABC12 ]---------- |---16M------[ DEF34 ] [ ABC12 ]-------- | [ ABC23 ]--------|---42m---[ DEF23 ] | [ ABC34 ]--------