in reply to replace first occurance if it doesn't already match
Heelo ddrew78,
Something like that?
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array = ("V12345:name_test", "V12345_name_test"); my @final = (); foreach my $str (@array) { if ($str =~ /[\w]+:/) { my @elements = split /:/, $str, 0; my $tmp = $elements[0] . "_" . $elements[1]; push @final, $tmp; } next; } print Dumper \@final; __END__ $ perl test_2.pl $VAR1 = [ 'V12345_name_test' ];
There are other ways I am sure but just an idea.
Hope this helps.
|
|---|