miRNA1a - results SOME DATA HERE ####### results end ######### miRNA2 - results ... and so on #### while (<>){ chomp; if (/^(miRNA\w+) - results/){ my $mirna_id = $1; while (<>){ chomp; last if /^####### results end #########/; # PARSE YOUR DATA HERE } } } #### my $current_mirna; while(<>){ chomp; $current_mirna = $1 if /^(miRNA\w+) - results/; die unless defined $current_mirna; # now you always have the miRNA ID of the current block # conitnue here to parse the actual data and insert into the # database for that specific miRNA }