my $path = $row; # path is the full string by default if ($row =~ /(.*),(.*)/) { my $left_part = $1; my $value = $2; # Check if $value is a number and change $path if needed ... }