If you want to avoid the error you've quoted, you need to avoid using an uninitialized value in concatenation (.) or string at ./thumb_test2.pl line 54. Of course, I have no idea which line is 54, but I'll bet it's one of the many of the form
my $hash = "$h[3]";. Assuming you are elevating warnings to errors, this will throw that error in cases where $h[3] is uninitialized, a.k.a. if line only had 3 elements for the example case. You could fix this by replacing that with
my $hash = defined $h[3] ? "$h[3]" : q{};
which will interpolate if the value is defined and will store an empty string (not an undef) in your variables.