Sorry - this was edited slightly to include the title. You need to declare the title variables too:
change
my ($next,$prev)
to
my ($next,$prev,$next_title,$prev_title)
change
my ($next,$prev)
to
my ($next,$prev,$next_title,$prev_title)