sub check { my $url = "http://google.com/?var1=aaaa&var2=aa"; my $count = 0; my @arr; return undef if $url !~ /^http:\/\/.*?\?.*?=.*?$/i; $count++ while $url =~ /&/g; $url =~ s/^(.*?=)(.*?)$/$1/ and return $url if $count<1; $arr[0..$count] = $url =~ /^http:\/\/.*?\?(?:([\w\d]*=)(?:.*[&]?))*/gi; say $_ foreach @arr; }