Resolved it!
There were ANSI characters to select the cursor position and put it in colors. There was no way to delete it in origin, the router.
Through other forum about perl programation they have given me the solution, find the character in the first line to start capture and discard everything before that point.
This is the part of the script to capture and edit the config
$telnet->print("screen-length 1000");
$telnet->print("page");
$telnet->print( "show running structured " );
####################QUITO CARACTERES ANSI##################
#Empezamos estando en la cabecera
my $en_cabecera = 1;
while (my $line = $telnet->getline())
{
#quitamos fin de linea
chomp $line;
#Si estamos $en_cabecera y la $line comienza por un ';'
if ($en_cabecera and $line =~ /^[;]/)
{
#Ya no estamos $en_cabecera
$en_cabecera =0;
}
#Si aun estamos $en_cabecera, saltamos a la liniea siguiente
next if $en_cabecera;
# get configuration content
if( $line !~ / Configuration Editor|Running configuration:|^\s*$/ )
{
$line =~ s/\s+$//g;
push @config, $line;
push @config, "\n";
}
}
$telnet->waitfor('/.*#/');
if( $telnet->errmsg )
{
$msg = "No prompt after 'display current-configuration': ".$telnet->errmsg;
$telnet->close( );
exit 258;
}
if( @config <= 0 )
{
$msg = "No data retrieved, the capture timeout may be too low.";
$telnet->close();
exit 252;
}
if( scalar grep {$_ =~ /^%/} @_ )
{
# Ensure show run actually returned the config and not an error message containing '%'
exit 253;
}
for( @config ) { print };
$telnet->close( );
exit 0;
}