#!/usr/local/bin/perl -i while ($line = <>) { while ($line =~ s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*##) { eval ("\$result = $&;"); $line =~ s//$result/; } print ($line); }