in reply to Bioinformatics, Error: explicit package name

This line is causing the syntax error:
my @third_fragments = grep -v ($rsite3), $second_fragments[$i]

Generally, Perl statements end with a semicolon. That being said, I think you are confusing Perl's built-in grep function with the unix grep utility. This is a common problem for new-comers. Simply adding the semicolon will not completely fix that line. You need to describe more fully what you are trying to achieve.