# remember to untaint $str open LOC, "/usr/bin/locate $str |" or die "Cannot open input pipe: $!\n"; while( ) { chomp; my $file = basename $_; next unless index($filename, $str) > -1; # output this filename } close LOC;