I have to create a loop, and with a regexp
populate any of the 4 variables
$address, $street, $town, $lot
The loop will be fed a string that may have info in it
like the lines below
'123 any street, mytown'or'Lot 4 another road, thattown'or'Lot 2 96 other road, her town'or'this ave, this town'or'yourtown'
since anything after a comma is the $town I thought
(.*), (.*)
then the first capture could be checked with (Lot \d*) (.*), (.*)
if the 1st capture starts with a number, then its the address (if word with white space its $street)
if one word, its just the $town
Take a look at Geo::StreetAddress::US if these are U.S. addresses.
Even if they are not, the source of this module should give you an idea of what is involved in parsing free form street addresses.
Here is a script that handles the addresses you posted (updated, earlier version combined lot and number into one string):
Output:
$VAR1 = [ { 'lot' => undef, 'number' => '123', 'street' => 'any street', 'town' => 'mytown' }, { 'lot' => 'Lot 4', 'number' => undef, 'street' => 'another road', 'town' => 'thattown' }, { 'lot' => 'Lot 2', 'number' => '96', 'street' => 'other road', 'town' => 'her town' }, { 'lot' => undef, 'number' => undef, 'street' => undef, 'town' => 'yourtown' }, { 'lot' => undef, 'number' => undef, 'street' => 'street', 'town' => 'town' } ];