You can also solve this using split and a positive lookahead assertion:
$string = "Name : somedata,123 Name : somedata1,234 Name :somedata3,345";
my @strings = split /(?=Name)/, $string;
print "<$_>\n" for @strings;
Outputs:
<Name : somedata,123 >
<Name : somedata1,234 >
<Name :somedata3,345>
Note, if the pattern is of zero width, then split will not match at the beginning of a string. For this reason, we do not need the positive look behind assertion to ensure that we aren't at the start.
Also, if we wanted to get rid of the trailing spaces, we could do that in the split as well:
my @strings = split /\s*(?=Name)/, $string;
split?splitin Perl? The function is literally namedsplit. perldoc.perl.org/functions/split.html