my $pos; if ( $string =~ m{(?=.*\Wcopyright(\W|ed\W)|\s\(c\)\s)} ) { $pos = pos( $string ) - 200; $pos = 0 if $pos < 0; } else { warn qq{Copyright text not found\n}; next; # or whatever } my $date = $1 if substr( $string, $pos, 400 ) =~ m{\D((?:19|20)\d\d)\D};