my @array; my $string = "/home/format_c"; $array[0] = "PATH = /homes/usr/"; $array[0] =~ s#(\w+\s+=\s+)/.*#$1 . $string#e; print $array[0];