I played around with this a bit and I think I know what's wrong.
use strict;
use warnings;
use Tk;
my $mw = new MainWindow(-title => 'TEST');
$mw->geometry("500x500");
my $canvas = $mw->Canvas(-width => 350, -height => 350,
-background => 'white')->pack();
my @arr1 = (10, 100, 200, 150, 250);
my $len = @arr1;
my $ver = $canvas->createLine(5, 5, 5, 250, -width => 4, -arrow => 'first',
-arrowshape => [5, 5, 5]);
my $hor = $canvas->createLine(3, 250, 250, 250, -width => 4, -arrow => 'last',
-arrowshape => [5, 5, 5]);
my $y = 20; my $n = 1; my $x = 0;
for (my $lp = 1; $lp < $len; $lp++) {
# the x+2 below and the $lp <= $len above caused indexing past the end of @arr1
# I changed it to $x+1 and $lp < $len - not sure if that's what's wanted, but no err.
my $id = $canvas->createLine($arr1[$x], $y, $arr1[$x+1], $y,
-width => 1, -arrow => 'both', -arrowshape => [3, 3, 3]);
my $tx = $canvas->createText(int (($arr1[$x] + $arr1[$x+1]) / 2), $y,
-text => $n);
$y += 10; $n++; $x++;
}
my $bt = $mw->Button(-text => 'Quit', -command => sub { exit; })->pack(
-side => 'bottom');
MainLoop;
__END__