$|=1; # So it works in the IDE
use autodie; # checks file opening for us...

# open files for reading and writing
open FILEIN, "< dmel.gff";
open FILEOUT, "> t_to_g.txt";

while(defined($line=<FILEIN>)){ # loop over file line by line
  @a = split /\t/,$line; # split the fields into an array
  if ($a[2] eq "mRNA"){ # only do for lines with info about mRNAs
    $a[8] =~ /ID=(FBtr\d+)/; # Get the Fbtr number from the 9th element of the array
    print FILEOUT "$1\t"; # print to the new file
    $a[8] =~ /Parent=(FBgn\d+)/; # Get the Fbgn number from the 9th element of the array
    print FILEOUT "$1\n"; # print to the new file
  }
}

close FILEIN;  # always good to close filehandles
close FILEOUT;

