The following works for the very limited test cases you've provided. Because I wasn't sure whether by "if there is a "_" after the numbers" you meant "immediately after the numbers", or just "somewhere after the numbers", I invented two more test cases, but I don't know if they represent what your strings actually look like. If you could provide more test cases, we could be of more help.
use warnings; use strict; use Test::More; sub subst { my $x = shift; $x =~ s/\d+[^_:]*\K_/:/; return $x; } is subst("V12345_name_test"), "V12345:name_test"; is subst("V12345:name_test"), "V12345:name_test"; is subst("V12345x_name_test"), "V12345x:name_test"; is subst("V12345x:name_test"), "V12345x:name_test"; # ... more test cases needed here! done_testing;
Update: Added the other two test cases. Added some more explanation.
In reply to Re: replace first occurance if it doesn't already match
by haukex
in thread replace first occurance if it doesn't already match
by ddrew78
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |