in reply to Push can shove it.

One thing that jumped out at me, not that it answers your question, is the regex substitution:

$pnum =~ s/0//;

which, admittedly will work as long as $pnum continues to always have a leading 0. What about a 100 page document? $pnum of 100 will become 10. Instead, you probably want:

$pnum =~ s/^0//;

or, even better:

$pnum =~ s/^0//;

which may actually be marginally faster (for what its worth), but more importantly won't break on page numbers 100+.

We now return you to your regularly scheduled discussion... :)