$canvas{width} = 8.5; $canvas{height} = 11; foreach(@pictures_to_canvas){ if ( ($canvas{width} > $$_{width}) && ($canvas{height} > $$_{width}) { $canvas{width} -= $$_{width}; $canvas{height} -= $$_{height}; } #Throw exception here if height or width goes below a min value. } ...