#!/usr/bin/perl -w use strict; my @leftCon = qw(left123 left456); my @rightCon = qw(right123 right456 right789); my %l_con; my %r_con; @l_con{@leftCon} = (1 .. @leftCon); @r_con{@rightCon} = (1 .. @rightCon); while () { next unless /:/; chomp; my ($ping1, $ping2) = split /:/; $ping1 =~ s/(?<=\d\d\d)\d+$//; $ping2 =~ s/(?<=\d\d\d)\d+$//; s/$ping1/$l_con{$ping1}."L"/e if defined $l_con{$ping1}; s/$ping2/$l_con{$ping2}."L"/e if defined $l_con{$ping2}; s/$ping1/$r_con{$ping1}."R"/e if defined $r_con{$ping1}; s/$ping2/$r_con{$ping2}."R"/e if defined $r_con{$ping2}; print $_," "; } print "\n"; __DATA__ left1232:right4562 right1234:right4563 right7895:left4565 right7891:left1232