# detect start of new data record my $FRAME_BEGINNING = qr/^Frame /; # store parsed Frame records my @frame_list; SKIP: while () { next SKIP if !/$FRAME_BEGINNING/; FRAME: while (!eof) { my %frame; DETAIL: while () { last DETAIL if /$FRAME_BEGINNING/; if (/^ *Source port: (\S+)\s+(\S+)/) { $frame{source_port} = $1; # also save $2? } if (/^ *Destination port: (\S+)\s+(\S+)/) { $frame{dest_port} = $1; } if (/^[\da-f]{4}\s+[\da-f\s]+/i) { push @{$frame{data}}, $_; # save data lines } } push @frame_list, \%frame; } }