use strict; use warnings; #### my %char_pics=(); # before the big loop while(){ ... foreach(@chars) { if(!$_ == "") { if (exists $char_pics{$_}) { $img= $char_pics{$_}; } else { $img=$pdf->image_png("/var/www/html/font_test/Pumpkins/$_.png"); $char_pics{$_}= $img; } vr->image(... ...