sub php_strstr { my $haystack = shift; my $needle = shift; my $before_needle = shift; my $i = index( $haystack, $needle ); # needle not found if ( $i == -1 ) { return undef; # or maybe ''; it's FALSE in php } # return substring before needle elsif ( $before_needle ) { return substr( $haystack, 0, $i ); } # return substring beginning with first found needle till end of string else { return substr( $haystack, $i ); } }