use warnings; use strict; use Data::Dumper; use Carp; my @aoa; my @temp; while () { chomp; if (/^Mtf (\d+) (.*) ([A-Z]+)$/) { # stuck here print "$_ \n"; push @temp, ($3); } elsif (/^>(\w+) St (b|f)\d+/) { # not sure how to capture only "f" here print "$_\n"; } push @aoa, [@temp]; } #print Dumper \@aoa ;