while () { if (/^%!PS-Adobe/) #Start of Page Marker { if ($found_match) { @linelist = reverse @linelist; while ($line = pop(@linelist)) { print $line; } $found_match = 0; } else { #Empty List undef @linelist; } } elsif(/^%%Title/) { for $z(@figlist) { if (/$z[A-Za-z]*\.eps/i) { $found_match = 1; } } } push @linelist, $_; }