/^somebegin(?!something)someend$/ #### if ( /^somebegin(.*)someend$/ ) { my $middle = $1; if ( $middle !~ /^something$/ ) { # woot } }