#!/home/ben/software/install/bin/perl use warnings; use strict; use File::Slurper 'read_text'; my @files = @ARGV; for my $file (@files) { my $text = read_text ($file); remove_trailing_ifs ($text); } exit; sub remove_trailing_ifs { my ($text) = @_; $text =~ s/ ^ (?\h*) (?\S.*) \s+ (?if|unless) \s+ (?.*) ; \s* $ /$+{leading_space}$+{type} ($+{condition}) { $+{leading_space} $+{action}; $+{leading_space}}/gxm; print $text; }