#!/usr/bin/perl use strict; my $data_pos = tell DATA; my $record; while (my $line = ) { chomp( $line ); $record = $line if ( $line =~ /^:16R:USECU/ ); } seek DATA, $data_pos, 0; while (my $line = ) { chomp( $line ); print "$line\n" if ( $record && $line =~/^:16S:GENL/ ); } __DATA__ :16S:LINK :16S:GENL :16R:USECU