The following code reads the content of a (simulated) file, extracts the two values and tests them. A regex is defined for each field. They are combined into a single regex which describes the rest of the line and specifies that both values should be extracted. If the match is successful, both values are tested.
use strict;
use warnings;
use Test::Simple tests => 3;
my $fname = \do {
my $line = "BOGUS PPI3_SYNY3 276 aa contentar BCT 13-NOV-2019\n";
};
open my $FH, '<', $fname or die "Cannot open $fname for input";
my $content = <$FH>;
close $FH;
my $get_bogus = qr/ [A-Z0-9_]+ /x;
my $get_acid = qr/ [0-9]+\s[a-z]+ /x;
my ( $bogus, $acids )
= $content =~ / BOGUS \s+ ($get_bogus) \s+ ($get_acid) /x;
if (ok( ( defined($bogus) and defined($acids) ), 'Match') ) {
ok( $bogus eq "PPI3_SYNY3" , "extracted '$bogus'");
ok( $acids eq '276 aa', "extracted '$acids'");
}
OUTPUT:
1..3
ok 1 - Match
ok 2 - extracted 'PPI3_SYNY3'
ok 3 - extracted '276 aa'