I just found out the "probably figure out on my own in due time" -- $filename wasn't getting assigned the value I thought it was.
I had written
$filename = (undef, undef, $images[$n]->{imagename}) = (File::Spec->splitpath( $_, 0 ));
Which causes $filename to always get the value 3. The (more) correct code is:
(undef, undef, $filename = $images[$n]->{imagename}) = (File::Spec->splitpath( $_, 0 ));
(There's probably a better way of doing in both cases, but I didn't feel like delving too deep into the depths of File::Spec).
Thanks,
James Mastros,
Just Another Perl Initate