#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use List::Util qw(first); my $file = 'test.txt'; my %frames_found; { 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 # get frame name my ($name) = $frame =~ m{\A [^\(\[]* [\(\[] (\w+) [\)\]] }x; # skip the frame when no name is given next if !$name; # check if user wants to get info about frame. Skip the frame if the # user didn't mentioned it next if !first{ $name eq $_ }@ARGV; # get all signals my @signals = grep{ $_ }$frame =~ m{^ \s* :+ 0x\d+ (.*?) \r?\n? $}xmg; my @found; for my $signal ( @signals ) { # skip signals that contains "FREI" or "(ID2)" next if index( $signal, 'FREI' ) != -1; next if index( $signal, '(ID2)' ) != -1; # skip signal if it does not contain _FA, or _A, next if $signal !~ m{ _F?A, }x; my ($value) = $signal =~ m{ \( ([^\)]+) \) }x; push @found, $value if $value; } $frames_found{$name} = @found ? \@found : 1; } close $fh; } print Dumper \%frames_found;