## untested, just a guess my @path; foreach my $path ( split( /:/, $ENV{PATH} ) ) { if( is_allowed_path($path) ) { ## whatever that means... push @paths, $path; } } push @paths, "/some/other/path"; $ENV{PATH} = join( ':', @paths ); #### delete $ENV{PATH}; $ENV{PATH} = "/path/to/tool;/some/other/path";