#!/usr/bin/perl -n BEGIN { use strict; use warnings; #use Data::Dumper; my $filename = $ENV{FILENAME}; unless (defined($filename)) {die "No filename in environment (filename)\n";} @ARGV = $filename; my $flag = '0'; my @lines; my $whole_match; my @part_before_match; my @part_after_match; my @number_of_matches; } if ( $_ =~ m// ) { $flag = '1'; } if ( $flag == '1' ) { $_ =~ s/\r\n//; $_ =~ s/\n//; $whole_match = $whole_match . $_ . " "; if ( $_ =~ m/<\/Text>/ ) { $flag = '0'; @number_of_matches = $whole_match =~ m/(Text>)/g; if ( scalar(@number_of_matches) > 2 ) { die "More then one Text in one line."; } @part_before_match = $whole_match =~ /(.*)(?=)/; @part_before_match->[0] =~ s/^ *$//g; @part_after_match = $whole_match =~ /(?<=<\/Text>)(.*)/; @part_after_match->[0] =~ s/^ *$//g; $whole_match =~ s/[^<]*//; $whole_match =~ s/<\/Text>.*//s; @lines = $whole_match =~ m/(.{1,4})/g; if ( defined @part_before_match && @part_before_match->[0] ne "") {print "@part_before_match\n";} #print Dumper @part_before_match; foreach my $line (@lines) { print " $line\n"; } if ( defined @part_after_match && @part_after_match->[0] ne "") {print "@part_after_match\n";} #print Dumper @part_after_match; undef @lines; undef $whole_match; undef @part_before_match; undef @part_after_match; undef @number_of_matches; } } else { print; }