#!/usr/bin/perl -w $file = $ARGV[0]; open(FILE, "file '$file' |"); $line = ; close(FILE); unless($line =~ /PDF document/) { print "Not converting $file\n"; exit(0); } print "Converting $file\n"; ((system("pdftotext '$file' - > /tmp/CONV.$$") / 256) == 0) or die "System failed."; system("mv /tmp/CONV.$$ '$file'");