use 5.16.2; my @finalnwlist = ( '192.169.32.0/255.255.255.0', '192.169.72.0/255.255.255.0', '192.169.73.0/255.255.255.0'); my @output = replace_exports(); use Data::Dumper; say Dumper \@output; sub replace_exports { chomp(my @lines = ); my @changes; foreach my $line (@lines) { foreach my $server (@finalnwlist) { my $output = $line; $output =~ s/\*/$server/g or next; push(@changes,$output); } } return @changes; } __DATA__ /file1 *(rw,sync,no_root_squash,no_subtree_check) /file2 *(ro,sync,no_root_squash,no_subtree_check) # shares for Tsp InstallServer file3 *(ro,sync,no_subtree_check)