Creo que esto debería hacer lo que necesitas: ```perl #!/usr/bin/env perl DMC: for my $dmc (1..14) { $t->print("querydmc $dmc"); my ($pmatch, $match) = $t->waitfor ( Match => '/>$/', Timeout => $timeout*3 ); if ($pmatch =~ /Specified DMC does not exist/) { next DMC; } my $modemReached = 0; my $modem = 'null'; my $subtitle; printf("%-10s|%-30s|%-30s\n", "MODEM","KEY","VALUE"); for my $line (split "\n", $pmatch) { $line =~ s/\s*\r$//; if ($line =~ /Modem:\s+([0-9]+)\s+(.*)/) { $modem = $1; $modemReached = 1; $subtitle = $2; } elsif ($modemReached) { $subtitle = $line; } if ($subtitle =~ /^\s*([^:]+):\s+(\S+( dBmV)?)\s+([^:]+):(.*)/) { my $key1 = $1; my $value1 = $2; my $key2 = $4; my $value2 = $5; printf("%-10s %-30s %-30s\n", $modem, $key1,$value1); printf("%-10s %-30s %-30s\n", $modem, $key2,$value2); } else { my ($key, $value) = split /:/, $line; $key =~ s/^\s+//; $value =~ s/^\s+//; printf("%-10s %-30s %-30s\n", $modem, $key,$value); } } } ``` La salida que te da por tu primera respuesta es: querydmc 1 MODEM |KEY |VALUE null Unit DMC 1 null Primary State IS null Secondary State null FW Load in RAM DDM50AK01 null FW Load in FLASH A DDM50AK01 null FW Load in FLASH B DDM50AK01 null Circuit Pack NTBN19EA null Serial Number FL000MF null Manufacturer's Date 06/JUN/2004 1 Primary State IS 1 Secondary State 1 DS CP 5 1 Spectrum_Chan_Code 1559 1 US CP 32 1 Spectrum_Chan_Code 80 1 TX LEVEL 50 dBmV 1 RX LEVEL 15 dBmV 2 Primary State IS 2 Secondary State 2 DS CP 9 2 Spectrum_Chan_Code 1551 2 US CP 6 2 Spectrum_Chan_Code 80 2 TX LEVEL 50 dBmV 2 RX LEVEL 8 dBmV