in reply to string matching

The issue is that you are escaping the carat - you are trying to match ^https instead of https. See perlre and/or perlretut. The correct code might look like

#!/usr/bin/perl use strict; use warnings; my $string = 'https://somewebsite.com/'; if ($string =~ /^https/) { print "https success\n"; } if ($string =~ /\/$/) { print "trailing slash success\n"; }

Note I have used an un-escaped carat as an anchor to require matches start at the beginning of the string - I assume this is where your confusion originated.

Depending on what you are trying to do, you may consider checking out some of the useful modules of CPAN, such as Regexp::Common::URI.

Replies are listed 'Best First'.
Re^2: string matching
by llancet (Friar) on Feb 26, 2010 at 02:59 UTC
    For work "do not have slash on end", I think this is better:
    if ( $str !~ m[/$] ) { # do something }
    which don't need to escape "/".