#!/usr/bin/perl use strict; use warnings; my @strings = ( '1. Foo::Bar', '2. Foo::Bar(', '3. Foo::Bar (', '4. Foo::Bar ' ); for ( @strings ) { print $_,$/ if /\w+::(?>\w+)(?!\s*\()/; } __END__ 1. Foo::Bar 4. Foo::Bar