Is there a way to do it ?
This is Perl, so TIMTOWTDI. In addition to haukex's approach with URI you could live a bit more dangerously and try any of these:
use strict;
use warnings;
use Test::More tests => 3;
my $have = 'https://abc.abc:8080/abc?abcdef&abc=&egh?';
my $want = 'https://def.def/abc?abcdef&abc=&egh?';
my $try = $have;
substr ($try, 8, 12, 'def.def');
is ($try, $want, 'substr');
($try = $have) =~ s/\Qabc.abc:8080/def.def/;
is ($try, $want, 'quotemeta regex');
my @bits = split ('/', $have, 4);
$bits[2] = 'def.def';
$try = join '/', @bits;
is ($try, $want, 'split/join');
There are plenty more too - this is just scratching the surface.
|