#!/usr/bin/perl use strict; use warnings; my $a = 'abc == 123'; if ($a =~ /^(.*?)==(.*)$/) { print "This will match\n"; print "First: $1\nLast: $2\n"; } if ($a =~ /^(.*?)\b==\b(.*)$/) { print "This will not match\n"; print "First: $1\nLast: $2\n"; }