sub get_record_from_file { my $filein = shift; my $regex = shift; my $pos = shift open FILEIN, "<$filein" or die "!$\n"; seek(FILEIN, $pos, 0); my $in_block = 0; my $last = "}"; my @array = {}; foreach my $line () { if ($line =~ /$regex/) { $in_block = 1; } if ($in_block) { push @array, $line; } if ($line =~ m/$last$/) { $in_block = 0; last; } } $pos = tell FILEIN; return (\@array, $pos); } my $curpos = 0; ($record,$curpos) = get_record_from_file("input.txt","DH:",$curpos);