use strict;
my $str = '|| ||Du Date||Done on||OK/NOK||Remarks||
|*Task 1*| | | | |
|*Task 2*| | | | |
|*Task 3*| | | | |
|*Task 4*| 15/03/23| | | See document X|';
my $regex = qr/.*\|\*(Task 1)\*\|(.*)\|(.*)\|(.*)\|(.*)\|.*\|\*(Task 2)\*\|(.*)\|(.*)\|(.*)\|(.*)\|.*\|\*(Task 3)\*\|(.*)\|(.*)\|(.*)\|(.*)\|.*\|\*(Task 4)\*\|(.*)\|(.*)\|(.*)\|(.*)\|/sp;
my $subst = '{"ACTION":[{"TITLE":"$1","DUE DATE":"$2","DONE ON":"$3","NOTE":"$5"},{"TITLE":"$6","DUE DATE":"$7","DONE ON":"$8","NOTE":"$10"},{"TITLE":"$11","DUE DATE":"$12","DONE ON":"$13","NOTE":"$15"},{"TITLE":"$16","DUE DATE":"$17","DONE ON":"$8","NOTE":"$20"}]}';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html