#!/usr/bin/perl use strict; use warnings; # file given as command line argument my $file = shift @ARGV; die "Usage: $0 \n" unless $file; # step 1: open the file open FH, "<", $file or die "Can't open '$file': $!\n"; # step 2: read the file line-by-line while () { # step 3: do the replacements s/<(\/?)H([12])>/<$1Heading $2>/g; # step 4: write the results the STDOUT print; } close FH;