in reply to subroutine problem
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";