in reply to subroutine problem

What is the value of @segment1 ?

And why are you assigning a string to an array in this line:

@pairs = "$segment1[$i-1]$segment1[$i]\n";

You probably mean to do:

$nn_pair = $segment1[$i-1] . $segment1[$i] . "\n";