"Use of uninitialized value in substr at line 19." But I can't figure out what value it's talking about.
Try adding use diagnostics; at the top of your program, you'll get a slightly longer explanation of errors and warnings. In this case the "uninitialized" warning means that one of the variables used had a value of undef, which happens e.g. when the variable has never been assigned anything, when you try to access array elements that you don't exist, or when the variable has been explicitly assigned undef at some point (see Declarations and undef). Also, another tool from the Basic debugging checklist is Data::Dumper, which makes it much easier to see your data structures (including undef). In this case you could have written print Dumper(\@contigfile,$element1,$element2); to see the current values of those variables.