#!/usr/bin/perl # perl -d ./perl_debugger.pl use strict; use Data::Dumper qw(Dumper); use File::Slurp; my @a_linesorig; my @a_out; my @a_str; my $line; my $reversedline; my @a_linesrev; my @reversedarray; my $reversedline; my $str; open(my $fh, "<", "data.txt") or die "cannot open < data.txt: $!"; my $line = read_file('data.txt'); @a_linesorig = split(' ', $line); @a_linesrev = reverse(@a_linesorig); $reversedline = join(' ', @a_linesrev); # joins the reversed list to a single string again @reversedarray = split( /solution/, $reversedline ); # should split huge string into a list from one solution to next foreach $str (@reversedarray) { if ($str =~ /\bdIonly:\b(.*?)\bworkset\b\\(\\(/g); print (@a_out, "$str"); } close $fh or die "can't close file: $!"; open(my $fh, ">", "output.txt") or die "cannot open > output.txt: $!"; foreach $str (@a_out) { print ($fh "$str\n"); } close $fh or die "can't close file: $!";