eval { $p->parse( ... ) }; if ($@ =~ /^Interrupted parsing/) { # The parse was stopped early. } sub whatever_handler { if ( $found_record ) { die "Interrupted parsing"; } }