Q:

How to interchange values of index in an array?

I am trying to match the strings inside an array and interchange the related values. But not able to form the logic.
@match = (
    "signal=signal_1 signal_2 signal_3", 
    "signal_1=signal_4 signal_5 abc", 
    "abc=signal_6 signal_7"
);

$i   = 0;
$num = @match;

while ( $i < $num ) {   

    $j = $i + 1;

    while( $j < $num ) {

        $match[$i] =~ s/=/ /g;
        $match[$j] =~ s/=/ /g;

        print($match[$i]);
        #print($match[$j]);

        @link1 = split / /, $match[$i];
        @link2 = split / /, $match[$j];

        #print(@link1);
        #print(@link2);

        for ( $i = 0; $i <= ($#link1); $i++ ) {

            if ( $link1[$i] =~ $link2[0] ) {
                # here I am missing the logic to interchange
            }
        }

        $j++;
        exit;
    }

    $i++;
}

The output array should be
@match = (
    "signal=signal_4 signal_5 abc signal_2 signal_3", 
    "signal_1=signal_4 signal_5 signal_6 signal_7", 
    "abc=signal_6 signal_7"
);

And is it possible to convert this array into a hash and interchange the matched keys and values?

A:

Yes, using a hash is much easier.
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

my @match = ('signal=signal_1 signal_2 signal_3',
             'signal_1=signal_4 signal_5 abc',
             'abc=signal_6 signal_7');

my %symbol;
@{ $symbol{ $_->[0] } }{ split ' ', $_->[1] } = ()
    for map { [ split /=/ ] } @match;

my $changed;
do {
    $changed = 0;
    for my $key (keys %symbol) {
        for my $value (keys %{ $symbol{$key} }) {
            if (exists $symbol{$value}) {
                my @news = keys %{ $symbol{$value} };
                for my $new (@news) {
                    next if exists $symbol{$key}{$new};

                    $changed = 1;
                    undef $symbol{$key}{$new};
                }
            }
        }
    }
} while $changed;

use Data::Dumper; warn Dumper \%symbol;

