my $p; for (split /,|;/, $ENV{PATH}){ m/\Wperl\W/i and $p=$_ }; print qq[===$p==\n]; # $p contains the path to perl