s/\.jpeg$/\.jpg/i; s/\.JPG$/\.jpg/i; if (-f "$d/$_") { $_="$_.jpg" unless (/\....$/); }