#!/usr/bin/perl use warnings; use strict; use Image::Magick; # largeimage.png is around 180 meg my $im = Image::Magick->new; # only make one object for my $i (0 .. 500) { print "$i\n"; test(); } sub test{ my $path = 'largeimage.png'; $im->Read($path); undef @$im; #needed if $im is created outside loop }