in reply to Regex to take an ip address before a comma

I would use

my $first = ( split /,\s*/, $line, 2 )[0]

to extract the first element.

I would do the test if $first is an ip address afterwards.

perldoc -f split