in reply to split string at variable position with matching

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11136666 use warnings; my $string = "hello my * name is Rob * and * I am a very nice person * + at least * I think * so"; my $x = 30; # or one less, not sure of the exact requirements my ($part1, $part2) = $string =~ /^(.{0,$x}\*)\s*(.*)/; print "$_\n" for $part1, $part2;

Outputs:

hello my * name is Rob * and * I am a very nice person * at least * I think * so