use strict; use warnings; my $operand = '[a-zA-Z0-9_]+' ; my $re = qr{ ^ # Beginning of string \s* # Optional whitespace ($operand) # Capture(1) Alphanumeric LHS \s* # Optional whitespace ( # Capture(2) either: [<>!]= # <=, >=, != | [<>=] # <, >, = ) \s* # Optional whitespace ($operand) # Capture(1) Alphanumeric LHS }x; while (my $line = ) { my ($lhs,$operator,$rhs) = $line =~ $re; if ($line =~ $re) { my ($lhs,$operator,$rhs) = ($1,$2,$3); printf " (%4s) (%2s) (%4s)\n", $lhs, $operator, $rhs; } } __DATA__ a=b a!=b ab a=>b a=