This code expects the filename as the first command line argument. For example, if the program is saved as "split.pl" in your home directory and the file to be processed is "MyDocument.pdf" on the desktop, launch
perl ~/split.pl ~/Desktop/MyDocument.pdf. See
shift and
@ARGV for more info. The processed file will be created near the source file, with ".clean" added before the file extension (MyDocument.clean.pdf in my example).