my $replace = (-f $ver_name ? "/$ver_name" : '') . '/abinitio/run'; (my $graph_dir = $before) =~ s{ /log/ .* \z }{$replace}xs;