#! perl use Modern::Perl; my ($foo, $bar, $baz, $mul, $op1, $op2); my $cr1 = sub { $foo = $bar * $baz; }; my $cr2 = sub { $foo = $bar * $baz; # Note whitespace differences }; my $cr3 = sub { $mul = $op1 * $op2; }; my $cr4 = sub { $foo = $baz * $bar; }; compare_subs($cr1, $cr2); compare_subs($cr3, $cr4); sub compare_subs { my ($s1, $s2) = @_; use B::Deparse; my $deparse = B::Deparse->new("-p", "-sC"); my $body1 = $deparse->coderef2text($s1); my $body2 = $deparse->coderef2text($s2); if ($body1 eq $body2) { say 'Identical'; } else { say 'Different'; } }