Win8 Strawberry 5.30.3.1 (64) Sun 05/23/2021 2:40:51 C:\@Work\Perl\monks >perl use 5.010; # need regex extended pattern \K use strict; use warnings; use autodie; my $data = <<'EOD'; module abc( rist_top_tck, rist_top_tdi, rist_top_tdo, EOD open my $fh, '<', \$data; while (my $line = <$fh>) { $line =~ s{ \A (\w+) \K (?= ,) }{($1)}xms; print $line; } close $fh; ^Z module abc( rist_top_tck(rist_top_tck), rist_top_tdi(rist_top_tdi), rist_top_tdo(rist_top_tdo),