Perl metacharacters

Saint Aardvark the Carpeted aardvark at
Sat May 29 16:53:02 PDT 2004

JJB disturbed my sleep to write:
> if (/(abuse\@.* )/)
>  {
>   $abuse_email = ${1};
>  }
> print($abuse_email) shows that it contains
> abuse at for probes, port scans etc.
> How do I change the if statement so I only get the abuse at
> string?

You want to minimize how much the bracket grabs.  Right now you're
telling it to grab as much as it can (".*"); a better solution would

	(/(abuse\@.*? )/)

which tells it to grab the smallest amount it can before the space.
Even better would be:


which grabs any word character, period, hyphen or underscore up to
a space.  Check your local listings to make sure I'm not leaving
out any characters legal for domain names.

> If (/(Net-.??-.??-.??-0-1)/)
>  {
>   $net_block = ${1};
>  }
> The data is (Net-xxx-xxx-xxx-0-1)
> Each xxx group will all ways by 1 to 3 digits long and different
> combinations every time.
> When matched I want $net_block just to hold  Net-xxx-xxx-xxx-0-1
> What is the correct syntax?

Something like:


BTW, you'd be better off emailing Perl questions to a Perl-related
mailing list or newsgroup, or posting them to

Saint Aardvark the Carpeted
aardvark at
Because the plural of Anecdote is Myth.

More information about the freebsd-questions mailing list