in reply to help shorten this series of regexes
The bigger picture would help a lot because hand parsing HTML like that is heading for a world of pain.
That said, and without knowing how the code fragment fits into the bigger picture, something like the following may help:
use strict; use warnings; my $str = 'Lumber:</td><td align="right"><b>10;'; my $str = 'Lumber:</td><td align="right"><b>10;'; my %hits; ++$hits{lc $1} if $str =~ /(lumber|clay|iron|crop):<\/td><td align="ri +ght"><b>\d+/i; print join ', ', sort keys %hits;
Prints:
lumber
Note in particular to use of a hash instead of a bunch of manifest variables.
|
|---|