use strict; use warnings; use Getopt::Std; my %opts = ( a => 0 ); getopts( q{a}, \ %opts ) or die qq{\n}; my %so = ( q{} => 0, B => 0, K => 1, M => 2, G => 3, T => 4, E => 5, P => 6, Z => 7, Y => 8, ); my $rcSortAscending = sub { my( $raA, $raB ) = @_; return $so{ $raA->[ 2 ] } <=> $so{ $raB->[ 2 ] } || $raA->[ 1 ] <=> $raB->[ 1 ] }; print map { my( $line, $path ) = @$_[ 0, 3 ]; if ( $path !~ m{/$} and -d $path and not -l $path ) { $line =~ s{\n}{/\n}; } $line; } sort { $opts{ a } ? $rcSortAscending->( $a, $b ) : $rcSortAscending->( $b, $a ) } map { [ $_, m{^\s*([\d.]+)([BKMGTEPZY]?)\s+(.*)} ] } <>;