my @leftCon; my @rightCon; while (<>) { /^\s*\[([^]]+)\]/ and push @leftCon, $1; /\[([^]]+)\]\s*$/ and push @rightCon, $1; } my $leftnoel = @leftCon; my $rightnoel = @rightCon; for (my $x = 0; $x <= $leftnoel-1; $x++) { # remove leading tab $leftCon[$x] =~ s/\t//g; $leftCon[$x] =~ s/\s+//g; } for (my $y = 0; $y <= $rightnoel-1; $y++) { # remove leading space char $rightCon[$y] =~ s/\s+//g; }