Perl like functionality for PHP