!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file = 'test.txt'; my @added_frames; my $line; { open my $fh, '<', $file or die "$file: $!"; # change block separator to have one complete frame # read per iteration local $/ = "\nFRAME NAME:"; # read the blocks while ( my $frame = <$fh> ) { next if $. == 1; # skip the "header" chomp $frame; # remove block separator (my $frame_name) = $line =~ /\s+([A-Z]+_[A-Z]+(?:[_ A-Z 0-9]+)?)[\)|\]|\,]/; print"\nmy frame name: $frame_name\n\n"; foreach $AddedFrame(@added_frames) { if($frame_name eq $AddedFrame) { if(($line =~ /::::0x/ and $line =~ /\(/) and ($line =~ /\_FA,/ or $line =~ /\_A,/)) { if($line =~ /FREI/ or $line =~ /ID2\)/) #ignore lines with "FREI" or "(ID2)" {} else { ( $_, $line) = split(/\(/,$line); #selects string after the opened bracket ( $_, $line) = split(/\)/,$line); #from the selected string, selects the one before the closed bracket @array = split(/, /,$line); print $out_dir $_, ";", "$array[1]\n"; #$countPar = $countPar +1; #count the number of mapping to } } } } # print the frame print "This is a frame:\n", '=' x 30, "\n", $frame, "\n", '=' x 30; } close $fh; }