my $https_img_path = 'https://123.123.123.255/images'; foreach my $image_url (@images){ # Split image from original path (relative or absolute) my ($path, $image) = split....... # Search the html ($file) for the images and replace them with my new paths. $file =~ s/$image_url/$https_img_path\/$image/ig; } # end of foreach.